9485: ABC217 —— D - Cutting Woods
[Creator : ]
Description
We have a long piece of timber with a length of $L$ meters.
For each $x = 1, 2, \dots, L - 1$, there is a mark called Mark $x$ at $x$ meters from the left end of the piece.
You are given $Q$ queries, the $i$-th of which is represented as a pair of numbers $(c_i, x_i)$.
Process the queries in ascending order of $i$ as described below.
- If $c_i = 1$: cut the piece at Mark $x_i$ into two.
- If $c_i = 2$: choose the piece with Mark $x_i$ on it and print its length.
Here, for both kinds of queries $c_i = 1, 2$, it is guaranteed that there will have been no cut at Mark $x_i$ when the query is to be processed.
For each $x = 1, 2, \dots, L - 1$, there is a mark called Mark $x$ at $x$ meters from the left end of the piece.
You are given $Q$ queries, the $i$-th of which is represented as a pair of numbers $(c_i, x_i)$.
Process the queries in ascending order of $i$ as described below.
- If $c_i = 1$: cut the piece at Mark $x_i$ into two.
- If $c_i = 2$: choose the piece with Mark $x_i$ on it and print its length.
Here, for both kinds of queries $c_i = 1, 2$, it is guaranteed that there will have been no cut at Mark $x_i$ when the query is to be processed.
Input
Input is given from Standard Input in the following format:
```
$L$ $Q$
$c_1$ $x_1$
$c_2$ $x_2$
$\vdots$
$c_Q$ $x_Q$
```
```
$L$ $Q$
$c_1$ $x_1$
$c_2$ $x_2$
$\vdots$
$c_Q$ $x_Q$
```
Output
Print the number of lines equal to the number of queries $c_i = 2$. In the $j$-th line, print the response to the $j$-th such query.
Constraints
- $1 \leq L \leq 10^9$
- $1 \leq Q \leq 2 \times 10^5$
- $c_i = 1, 2$ $(1 \leq i \leq Q)$
- $1 \leq x_i \leq L - 1$ $(1 \leq i \leq Q)$
- For every $i$ $(1 \leq i \leq Q)$, the following holds: there is no $j$ such that $1 \leq j \lt i$ and $(c_j,x_j) = (1, x_i)$.
- All values in input are integers.
- $1 \leq Q \leq 2 \times 10^5$
- $c_i = 1, 2$ $(1 \leq i \leq Q)$
- $1 \leq x_i \leq L - 1$ $(1 \leq i \leq Q)$
- For every $i$ $(1 \leq i \leq Q)$, the following holds: there is no $j$ such that $1 \leq j \lt i$ and $(c_j,x_j) = (1, x_i)$.
- All values in input are integers.
Sample 1 Input
5 3
2 2
1 3
2 2
Sample 1 Output
5
3
At the time of the first query, no cut has been made, so the piece with Mark 2 has a length of 5 meters. Thus, you should print 5.
In the second query, the piece is cut into two pieces with lengths of 3 and 2 meters.
At the time of the third query, the piece with Mark 2 has a length of 3 meters, so you should print 3.
In the second query, the piece is cut into two pieces with lengths of 3 and 2 meters.
At the time of the third query, the piece with Mark 2 has a length of 3 meters, so you should print 3.
Sample 2 Input
5 3
1 2
1 4
2 3
Sample 2 Output
2
Sample 3 Input
100 10
1 31
2 41
1 59
2 26
1 53
2 58
1 97
2 93
1 23
2 84
Sample 3 Output
69
31
6
38
38