#P4036. [JSOI2008] 火星人
[JSOI2008] 火星人
Description
Martians have recently been studying an operation: finding the common prefix of two suffixes of a string.
For example, consider this string: madamimadam. We label its characters as follows:
序号 1 2 3 4 5 6 7 8 9 10 11
字符 m a d a m i m a d a m
Now, Martians define a function , which means: the length of the common prefix between the substring starting at the -th character and the substring starting at the -th character of the string. For example, .
In the process of studying the function, Martians found a connection: if you sort all suffixes of the string, you can quickly compute the value of ; likewise, if you know the values of , you can quickly sort the suffixes of the string.
Although Martians cleverly discovered a fast algorithm for computing , the unyielding Earthlings posed a new challenge: while computing , the string itself may change. Specifically, you may change the value of a character in the string, or insert a character at some position in the string. The Earthlings want to test whether Martians can still compute quickly under such a complex scenario.
Input Format
The first line gives the initial string. The second line is a non-negative integer , the number of operations. The next M lines each describe one operation. There are 3 types of operations:
- Query. Syntax: , where , are positive integers. Function: compute . Constraint: current string length.
- Modify. Syntax: , where is a positive integer and is a character. Function: replace the -th character of the string with . Constraint: does not exceed the current string length.
- Insert. Syntax: , where is a non-negative integer and is a character. Function: insert character after the -th character of the string; if , insert at the beginning of the string. Constraint: does not exceed the current string length.
Output Format
For each query operation in the input, output the corresponding answer, one per line.
madamimadam
7
Q 1 7
Q 4 8
Q 10 11
R 3 a
Q 1 7
I 10 a
Q 2 11
5
1
0
2
1
Hint
- All strings always consist of lowercase letters only.
- The string length always satisfies .
- The number of query operations does not exceed .
For testdata 1 and 2, the string length never exceeds . For testdata 3, 4, and 5, there are no insert operations.
Translated by ChatGPT 5
京公网安备 11011102002149号