#P17704. [ICPC 2019 Nanjing R] Paper Grading
[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 strings in lowercase letters, denoted by 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 in lowercase letters together with three integral coefficients and . The student's final score should be the number of strings in the Book of Requirement with such that the longest common prefix of and is of length at least .
Input Format
The first line contains two integers and () where is the number of strings in the Book of Requirement and is the total number of modifications and students.
The following lines are non-empty strings indicating all string in the book, whose total length is up to .
Then the following lines describe all modifications and students that are asked to grade in time sequence. Each line of them starts with an integer . If , it follows two integers and describing a modification to swap the -th and the -th string in the book, where and can be equal to . If , it follows a non-empty string and three non-negative integers and , where and , representing a student as above.
It is guaranteed that the total length of provided in the input is up to .
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 and . For the first given student with the string , the longest common prefixes with and are of length at least . Hence his final score is . For the second student, the only available string to consider in the book is the first one .
Then a modification comes, and strings in the Book of Requirement become and . For the third student, both and have a common prefix with given of length . Hence the answer is .