Cake
Time limit2sMemory limit1024 MB
Starting from piece a, Leopold always eats the less delicious piece next to the empty interval, and each query asks how many pieces are eaten before piece b.
- Level
Hard9 of 10
- Topics
- Segment tree, Divide and conquer, Greedy, Simulation
- Solved
- No attempts yet
Problem
Leopold and Molly both love cake. Leopold loves eating it, and Molly loves watching Leopold eat it. Today they bought pieces of seed cake. The pieces lie in a row on a narrow plate that has positions. The positions are numbered to from left to right, and piece lies on position .
Leopold cares about how delicious the pieces are. The initial deliciousness of piece is . He starts with piece , which leaves position empty. After that he always eats the least delicious piece next to an empty position, so the empty positions always form one closed interval. Molly sometimes puts a topping on a piece to make it more delicious. She always does so in a way that makes the piece one of the 10 most delicious pieces. No two pieces are equally delicious at any time.
Molly sometimes wonders how many pieces Leopold eats before he eats piece , assuming she adds no further toppings. Write a program that processes instructions of two kinds: make a piece more delicious, and report how many pieces Leopold eats before a given piece.
A query does not actually consume any cake. Each query considers the eating process started again from piece with the deliciousness values as they stand at that moment.
Input
The first line contains the number of pieces () and the piece () that Leopold eats first. The second line contains the initial deliciousness values . They are pairwise distinct and satisfy . The third line contains the number of instructions (). Each of the next lines contains one instruction of one of the two kinds below.
E i e(the characterEfollowed by two integers and ): piece is enhanced so that it becomes the -th most delicious piece. The deliciousness order of the other pieces does not change. Before the enhancement, at least pieces are more delicious than piece .F b(the characterFfollowed by an integer ): report how many pieces Leopold eats before he eats piece .
Output
For each F instruction, in the order the instructions appear in the input, print one line with a single integer: the requested number of pieces.
Limits
- ,