#P17704. [ICPC 2019 Nanjing R] Paper Grading

    ID: 20156 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>2019cdq 分治可持久化哈希 hashing分块字典树 TrieICPC南京离线处理

[ICPC 2019 Nanjing R] Paper Grading

Problem Description

The story is purely fictitious.

Nearly all the students in No.84 University are asked to take a compulsory course called JL and pass the exam, which says that hundreds of students will take part in this final exam together. The teacher organizing the course is always trying to find a more efficient and fair way to grade students' test papers. In this year, you are appointed to write a program to grade papers.

Now you are given the Book of Requirement which is a dictionary consists of nn strings in lowercase letters, denoted by s1,s2,⋯ ,sns_1, s_2, \cdots, s_n in order. However, the book as a magic item may be modified with exchanges. It is possible to swap the positions of two strings inside the dictionary at any time. For instance, if one swap the first and the fifth strings, the so-called first string in this dictionary after the modification would be the fifth one originally.

The scoring criterion is given as follow. A student and his/her test paper are described as a string qq in lowercase letters together with three integral coefficients k,lk, l and rr. The student's final score should be the number of strings sis_i in the Book of Requirement with l≤i≤rl \le i \le r such that the longest common prefix of qq and sis_i is of length at least kk.

Input Format

The first line contains two integers nn and mm (1≤n,m≤2×1051 \le n, m \le 2 \times 10^5) where nn is the number of strings in the Book of Requirement and mm is the total number of modifications and students.

The following nn lines are nn non-empty strings s1,s2,⋯ ,sns_1, s_2, \cdots, s_n indicating all string in the book, whose total length is up to 2×1052 \times 10^5.

Then the following mm lines describe all modifications and students that are asked to grade in time sequence. Each line of them starts with an integer opt (1≤opt≤2)opt~(1 \le opt \le 2). If opt=1opt=1, it follows two integers ii and jj describing a modification to swap the ii-th and the jj-th string in the book, where 1≤i,j≤n1 \le i, j \le n and ii can be equal to jj. If opt=2opt=2, it follows a non-empty string qq and three non-negative integers k,lk, l and rr, where 0≤k≤∣q∣0 \le k \le |q| and 1≤l≤r≤n1 \le l \le r \le n, representing a student as above.

It is guaranteed that the total length of qq provided in the input is up to 2×1052 \times 10^5.

Output Format

For each student, output a single line containing the score of his/her test paper.

3 4
aaa
bbb
aac
2 aasdd 2 1 3
2 aab 1 1 2
1 2 3
2 aat 2 1 2
2
1
2

Hint

In the example, the initial Book of Requirement consists of s1=aaa,s2=bbbs_1= aaa ,s_2= bbb and s3=aacs_3=aac. For the first given student with the string q=aasddq=aasdd, the longest common prefixes with aaaaaa and aacaac are of length at least 22. Hence his final score is 22. For the second student, the only available string to consider in the book is the first one s1=aaas_1=aaa.

Then a modification comes, and strings in the Book of Requirement become s1=aaa,s2=aacs_1=aaa,s_2=aac and s3=bbbs_3=bbb. For the third student, both s1s_1 and s2s_2 have a common prefix with given q=aatq=aat of length 22. Hence the answer is 22.