#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 nn pieces of cake in a row. The ii-th cake from left to right is labeled ii, and each cake has a deliciousness value did_i.

Leopold will first eat the cake labeled aa, leaving position aa 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 1010 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 bb, 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 n,an, a, representing the total number of cakes and which cake Leopold eats first.
The second line contains nn pairwise distinct positive integers d1,d2,,dnd_1, d_2, \ldots, d_n, representing the initial deliciousness values.
The third line contains a positive integer qq, representing the number of operations.
The next qq lines each describe an operation in the form E i e or F b:

  • E i e: Increase the deliciousness of cake ii to be the ee-th most delicious. It is guaranteed that before the operation, the number of cakes more delicious than cake ii is at least ee.
  • F b: Ask how many cakes Leopold will eat before eating cake bb.

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 3,2,4,5,13, 2, 4, 5, 1 will be eaten in this order. But after that, cake 11 becomes so delicious that it will not be eaten earlier, and cakes 44 and 55 are eaten first. Note that the last increase in deliciousness of cake 55 will not change the eating order.

Constraints and Notes

For all testdata, it is guaranteed that 1n2.5×1051 \le n \le 2.5 \times {10}^5, 1q5×1051 \le q \le 5 \times {10}^5, 1di,a,i,bn1 \le d_i, a, i, b \le n, and 1e101 \le e \le 10.

Subtask ID Score Special Constraints
11 1515 n,q104n, q \le {10}^4
22 n2.5×104n \le 2.5 \times {10}^4 and the number of F operations does not exceed 500500
33 2020 q105q \le {10}^5 and the number of E operations does not exceed 100100
44 5050 No special constraints.

Translated by ChatGPT 5