#P5561. [Celeste-B] Mirror Magic
[Celeste-B] Mirror Magic
Description
The Mirror Temple is a magical temple, where you can catch a glimpse of the truth in your heart.
Theo is trapped inside a mirror. When Madeline tries to save Theo, the “creatures” in the temple give her a difficult puzzle. The puzzle is as follows:
The “creatures” prepare strawberry strings, and the sum of their lengths . Now they can perform the following operations:
means copying the substring of the strawberry string with index , and inserting the copied string into the current set of strawberry strings. It is guaranteed that the length of string is .
means deleting the strawberry string that was inserted by the -th operation. It is guaranteed that the -th operation is an insertion, and the string inserted by the -th operation is currently in the set.
The “creatures” believe that a harmonious flavor is delicious. After performing any operation, they want to know the deliciousness of all strawberry strings in the current set (i.e., - the longest common prefix). (If the set is empty, the deliciousness is . If there is only one strawberry string in the set, the deliciousness is the length of that string.)
For convenience, we represent each type of strawberry as a lowercase English letter.
Many years later, Madeline comes to the Mirror Temple again, wanting to recall her climbing journey from long ago, but she no longer remembers how she solved that puzzle back then. Can you help her find the answer to the puzzle?
Input Format
The first line contains a positive integer , indicating the number of strawberry strings.
The next lines each contain a string consisting of only lowercase letters, representing the original strawberry strings.
The next line contains a positive integer , indicating the number of operations.
The next lines each contain one operation.
Output Format
Output lines. Each line should be the deliciousness ( - the longest common prefix) of the strawberry strings in the set after the corresponding operation.
3
abccccd
abccddc
acbbcad
5
1 1 1 7
1 2 1 7
1 3 1 7
2 3
2 2
7
4
1
4
7
Hint
Sample explanation:
After the first operation, the set is , .
After the second operation, the set is , .
After the third operation, the set is , .
The fourth operation deletes the string inserted by the third operation, so .
The fifth operation deletes the string inserted by the second operation, so .
Let be the sum of lengths of the strings. We always have .
Subtask ( Pts): .
Subtask ( Pts): , and it is guaranteed that each insertion is a prefix of a string.
Subtask ( Pts): , there are no type operations, and it is guaranteed that the queries are randomly generated.
Subtask ( Pts): .
Hint: You can determine the subtask number based on .
Translated by ChatGPT 5
京公网安备 11011102002149号