#P15122. [ICPC 2024 LAC] Harmonic Operations
[ICPC 2024 LAC] Harmonic Operations
题目描述
In this problem we consider three types of operations that can be applied to any 0-based string of length .
- : Reverses .
- : Rotates to the right positions, for some positive integer . That is, for each , the character at position in is the character at position in .
- : Analogous to , but rotates to the left instead of to the right.
For example, , , and . Note that for any and any it holds that .
When a list of the above operations is applied to a string, it is done sequentially in list order. That is, the first operation of the list is applied to the original string, the second operation is applied to the result after having applied the first operation, the third operation is applied to the result after having applied the first two operations, and so on.
You are given a string consisting of lowercase letters, and a list of operations . Your task is to find out how many pairs of indices there are such that , and applying the sublist of operations to yields as the final result.
Consider for instance , , and . The result of applying the sublist to is , which is different from . The result of applying the sublist to is $L(R(\text{“pda”}, 2), 2) = L(\text{“dap”}, 2) = \text{“pda”} = S$. Finally, the result of applying the sublist to is , which is different from . Thus, in this example the answer is 1.
输入格式
The first line contains a string () which is made up of lowercase letters.
The second line contains an integer () indicating the number of operations in the list of operations that is being considered.
Operations are described in the next lines, in the order they appear in the list, one operation per line. If the operation is , the line contains the uppercase letter “I”. If the operation is , the line contains the uppercase letter “R” and the integer (). Finally, if the operation is , the line contains the uppercase letter “L” and the integer ().
输出格式
Output a single line with an integer indicating the requested number of pairs.
pda
2
R 2
L 2
1
aaa
4
R 1
I
I
R 1
10
caso
6
L 1
I
I
R 1
I
I
4