#P6544. [CEOI 2014] Cake
[CEOI 2014] Cake
Description
Both Leopold and Molly like cakes: Leopold likes eating cakes, and Molly likes watching Leopold eat cakes.
There are pieces of cake in a row. The -th cake from left to right is labeled , and each cake has a deliciousness value .
Leopold will first eat the cake labeled , leaving position empty. After that, each time he will choose, among the cakes adjacent to the empty position, the cake with the smallest deliciousness and eat it (saving the tastier ones for later). You can observe that the empty positions will always form a continuous interval.
To make things more interesting, Molly sometimes adds a bit of decoration to one cake to increase its deliciousness. She guarantees that after this operation, this cake’s deliciousness will become one of the top among all cakes. Also, at any time, the deliciousness values of any two cakes are different.
Sometimes Molly is curious: before Leopold eats a specific cake labeled , how many cakes will he have eaten?
Please help Molly write a program that, given a sequence of operations, answers Molly’s queries.
Input Format
The first line contains two positive integers , representing the total number of cakes and which cake Leopold eats first.
The second line contains pairwise distinct positive integers , representing the initial deliciousness values.
The third line contains a positive integer , representing the number of operations.
The next lines each describe an operation in the form E i e or F b:
E i e: Increase the deliciousness of cake to be the -th most delicious. It is guaranteed that before the operation, the number of cakes more delicious than cake is at least .F b: Ask how many cakes Leopold will eat before eating cake .
Output Format
For each F operation, output one line with one number, representing the answer.
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
Hint
Sample Explanation
Before the first increase in deliciousness, the cakes labeled will be eaten in this order. But after that, cake becomes so delicious that it will not be eaten earlier, and cakes and are eaten first. Note that the last increase in deliciousness of cake will not change the eating order.
Constraints and Notes
For all testdata, it is guaranteed that , , , and .
| Subtask ID | Score | Special Constraints |
|---|---|---|
and the number of F operations does not exceed |
||
and the number of E operations does not exceed |
||
| No special constraints. |
Translated by ChatGPT 5
京公网安备 11011102002149号