#P3968. [TJOI2014] 电源插排
[TJOI2014] 电源插排
Description
There are many power strips in Xiao M’s lab. The outlets are indexed from to , arranged in a line from left to right.
Every morning, all outlets are unused. Each time a student comes to the lab, they plug their laptop’s power into some unused outlet.
The students follow a peculiar rule: first, they find the longest contiguous segment of unused outlets.
If there are multiple segments with the same length, they choose the rightmost one. Then they plug into the middle of that segment.
If the segment length is even, they pick the right middle position (i.e., the right one). When a student leaves the lab, they unplug their power.
It is guaranteed that whenever a student arrives, there is at least one empty outlet.
You need to answer how many outlets are already in use within the interval .
Input Format
The first line contains two integers and , the number of outlets and the number of queries.
Then follow lines. Each line starts with an integer .
If is , it is followed by two integers and , indicating a query.
Otherwise, indicates that the student with ID arrives or leaves. The st appearance of means arrival, the nd appearance means departure, and so on. Each student ID is unique.
Output Format
For each query, output one integer: the number of outlets already in use within the query interval.
7 10
1
2
3
0 1 2
0 4 7
0 2 5
20
0 6 6
99
0 4 6
1
2
2
1
3
Hint
Constraints
For of the testdata, .
For of the testdata, $1 \le n \le 10^9, 1 \le q \le 10^5, 0 \le k \le 10^9, 1 \le l \le r \le n$.
Translated by ChatGPT 5
京公网安备 11011102002149号