|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||1024 MB||2||2||2||100.000%|
Leopold and Molly love cake: While Leopold loves eating cake, Molly loves watching Leopold eat cake. Today, they have bought N pieces of seedcake. The pieces are on a narrow plate with N cake piece positions in a row. From left to right, the positions are numbered from 1 to N. Also the pieces are numbered, with piece i on position i.
When eating cake, Leopold considers how delicious the pieces are. For each piece i, he exactly knows about its initial deliciousness value di. He starts with some piece a; then, position a is empty. After that, the next piece he eats is always the least delicious piece next to any empty position. Hence, at any time, all empty positions are from a single closed interval. To make things even more interesting, Molly occasionally adds a topping to some piece to enhance its deliciousness. She will always do so in a way that makes the piece one of the 10 most delicious pieces. At any time, no two pieces will be equally delicious.
Sometimes, Molly wonders how many of the pieces Leopold will eat before he eats a certain piece b—assuming there are no future enhancements. Help Molly and write a program that can process instructions of the form “enhance a piece” or “find the number of pieces Leopold will eat before a certain piece”.
The first line contains the two integers N (1 ≤ N ≤ 250 000), the number of pieces, and a (1 ≤ a ≤ N), the piece Leopold will eat first. The second line contains N mutually distinct integers 1 ≤ d1, . . . , dN ≤ N, the initial deliciousness values of the pieces. The third line contains 1 ≤ Q ≤ 500 000, the number of instructions to process. Each of the next Q lines contains an instruction of one of the following two types:
For each instruction of type “F”, in the order as these instructions appear in the input, output a line that contains a single integer: the requested number of pieces.
N, Q ≤ 10 000
N ≤ 25 000, and there are at most 500 instructions of type “F”.
Q ≤ 100 000, and there are at most 100 instructions of type “E”.
No further constraints.
5 3 5 1 2 4 3 17 F 1 F 2 F 3 F 4 F 5 E 2 1 F 1 F 2 F 3 F 4 F 5 E 5 2 F 1 F 2 F 3 F 4 F 5
4 1 0 2 3 4 3 0 1 2 4 3 0 1 2