QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 128 MB Puntuación total: 100

#15244. Power Strip

Estadísticas

Small M's laboratory has many power strips. These power strips are numbered from $1$ to $N$ and are arranged in a row from left to right.

Every morning, these power strips are unused. When a student arrives at the laboratory, they plug their laptop into an unused power strip. The students in the laboratory are very curious, and they complete this process as follows: First, they find the longest interval of unused power strips. If there are multiple intervals of the same length, they choose the one furthest to the left. Then, they plug their power cord into the middle of that interval. If the interval length is even, they also choose the one furthest to the left. When a student leaves the laboratory, they unplug their power cord. It is guaranteed that when a student arrives at the laboratory, there is at least one empty power strip.

Now, you are given the arrival and departure events of the students, as well as some queries. For each query, you need to calculate how many power strips have been used in the interval $[L, R]$.

Input

The first line contains two integers $N$ and $Q$, representing the number of power strips and the number of queries. Then $Q$ lines follow. Each line starts with an integer $K$. If $K=0$, it is followed by two integers $L$ and $R$ ($1 \le L \le R \le N$), representing a query. Otherwise, it represents student $K$ ($K \le 10^9$) arriving or leaving. If student $K$ has appeared an odd number of times, they are arriving; if an even number of times, they are leaving. Each student's ID is unique.

Output

For each query, output a single integer representing how many power strips have been used in the interval $[L, R]$.

Examples

Input 1

7 10
1
2
3
0 1 2
0 4 7
0 2 5
20
0 6 6
99
0 4 6

Output 1

1
2
2
1
3

Constraints

For $30\%$ of the data, $N \le 10^5, Q \le 10^3$. For $100\%$ of the data, $N \le 10^9, Q \le 10^5$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.