#P5287. [HNOI2019] JOJO
[HNOI2019] JOJO
Description
To prevent too many words from blocking the manga content, the new manga plans to use Ora or Muda to represent that there are occurrences of Ora or Muda.
To simplify the content, we now use letters to represent the shouted words.
We use numbers and letters to represent a string. For example, 2 a 3 b represents the string .
At the beginning, there is no text in the manga. Next, you need to perform operations in order. There are only types of operations in total:
- The first type:
1 x cadds copies of to the current manga, meaning appending characters to the end of the current string. It is guaranteed that the current string is empty, or the last character of the string is not . - The second type:
2 xthinks the manga was not drawn well and restores it to the state after the -th operation, meaning restoring the string to the state after the -th operation. If , the string becomes the empty string.
If the current string is , and after the -th operation the string is , then 2 4 will change into . It is guaranteed that is less than the current operation index.
As everyone knows, Jotaro Kujo is very smart. Now that Dio has been defeated, he starts thinking about some problems in his manga:
For each prefix of a string, there is a longest prefix that is shorter than it and matches a suffix of prefix . Let the length of this longest prefix be . When is , it means is an empty string.
After each operation, you need to compute the sum of over all prefixes of the current string, take it modulo , and output it to tell Jotaro Kujo, so that he can compare it with the answer computed by his Star Platinum.
For example, for , the values of are , so the answer for this string is .
Input Format
The first line contains a positive integer , representing the number of operations.
The next lines each contain one operation. The operation formats are as described in the statement, for example:
1 x c2 x
It is guaranteed that the input is valid.
Output Format
The output contains exactly lines. The -th line contains one integer, representing the answer after the first operations.
11
1 2 a
1 3 b
1 2 a
1 1 b
2 2
1 3 a
1 2 b
2 6
2 5
1 7 a
1 5 c
1
1
4
7
1
6
13
6
1
14
14
Hint
Sample Explanation
| Operation | Current string | Answer |
|---|---|---|
aa |
||
aabbb |
||
aabbbaa |
||
aabbbaab |
||
aabbb |
||
aabbbaaa |
||
aabbbaaabb |
||
aabbbaaa |
||
aabbb |
||
aabbbaaaaaaa |
||
aabbbaaaaaaaccccc |
Constraints
of the testdata satisfies and for each operation of type , .
Another of the testdata satisfies and for each operation of type , .
Another of the testdata satisfies and contains no operation of type .
of the testdata satisfies and for each operation of type , .
Translated by ChatGPT 5
京公网安备 11011102002149号