#P4130. [NOI2007] 项链工厂
[NOI2007] 项链工厂
Description
A necklace contains beads. Each bead’s color is one of . The necklace is fixed on a flat board. Some point on the board is marked as position , and in the clockwise direction the other positions are labelled .

The software system you will write should support the following commands:


Input Format
The first line contains two integers , representing the number of beads in the necklace and the number of colors, respectively.
The second line contains integers, , representing the colors of the beads from position to position , where .
The third line contains an integer , representing the number of commands.
Each of the next lines contains one command, as described above.
Output Format
For each C and CS command, output one integer representing the corresponding answer.
5 3
1 2 3 2 1
4
C
R 2
P 5 5 2
CS 4 1
4
1
Hint
[Constraints and Conventions]
For 60% of the testdata, , .
For 100% of the testdata, , , .
About rotation and flip
Note that the rotation command rotates the beads but does not change the labels of the positions, and the flip command is always symmetric about position . For example, when , the position labels on the necklace are as shown in Figure 1:
However, note that the position labels on the necklace still remain as shown in Figure 1, so the axis of symmetry for flipping does not change. Therefore, after executing another “F” command, the colors on the necklace are as shown in Figure 4.


About the CountSegment command
The CS command queries how many “segments” there are in a linear “segment” of the necklace. In particular, when the query length equals , we still treat the query range as a linear “segment”.
For example, in the situation shown in Figure 4, executing the command CS 1 10 queries how many “segments” there are in the linear segment starting at position and ending at position , which has length , and the return value is . In contrast, if you execute the C command, the return value would be .
Translated by ChatGPT 5
京公网安备 11011102002149号