#P1503. 鬼子进村
鬼子进村
Description
There are houses in the county connected by tunnels in a line. The -th house is connected only to the -th and -th houses. Specifically, house is connected only to house , and house is connected only to house . There are messages arriving in order:
- If the message is
D x: the enemy destroys house , and the tunnel is blocked. - If the message is
R: the villagers repair the most recently destroyed house. - If the message is
Q x: a soldier is trapped in house .
Define reachability as follows: if there exist houses () such that for every with , house is not destroyed, then house and house are mutually reachable.
Li Yunlong is nervous after receiving the information. He wants to know, for each trapped soldier, how many houses he can reach.
Input Format
The first line contains two integers .
Each of the next lines contains one of the three messages described above.
Output Format
For each trapped soldier, output the number of houses he can reach.
7 9
D 3
D 6
D 5
Q 4
Q 5
R
Q 4
R
Q 4
1
0
2
4
Hint
Constraints
.
If a soldier is trapped in a destroyed house, he can only wait to die.
Translated by ChatGPT 5
京公网安备 11011102002149号