100 #ABC217D. [ABC217D] Cutting Woods

[ABC217D] Cutting Woods

Score : 400400 points

Problem Statement

We have a long piece of timber with a length of LL meters. For each x=1,2,,L1x = 1, 2, \dots, L - 1, there is a mark called Mark xx at xx meters from the left end of the piece.

You are given QQ queries, the ii-th of which is represented as a pair of numbers (ci,xi)(c_i, x_i). Process the queries in ascending order of ii as described below.

  • If ci=1c_i = 1: cut the piece at Mark xix_i into two.
  • If ci=2c_i = 2: choose the piece with Mark xix_i on it and print its length.

Here, for both kinds of queries ci=1,2c_i = 1, 2, it is guaranteed that there will have been no cut at Mark xix_i when the query is to be processed.

Constraints

  • 1L1091 \leq L \leq 10^9
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • ci=1,2c_i = 1, 2 (1iQ)(1 \leq i \leq Q)
  • 1xiL11 \leq x_i \leq L - 1 (1iQ)(1 \leq i \leq Q)
  • For every ii (1iQ)(1 \leq i \leq Q), the following holds: there is no jj such that 1j<i1 \leq j \lt i and (cj,xj)=(1,xi)(c_j,x_j) = (1, x_i).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

LL QQ

c1c_1 x1x_1

c2c_2 x2x_2

\vdots

cQc_Q xQx_Q

Output

Print the number of lines equal to the number of queries ci=2c_i = 2. In the jj-th line, print the response to the jj-th such query.

5 3
2 2
1 3
2 2
5
3

At the time of the first query, no cut has been made, so the piece with Mark 22 has a length of 55 meters. Thus, you should print 55. In the second query, the piece is cut into two pieces with lengths of 33 and 22 meters. At the time of the third query, the piece with Mark 22 has a length of 33 meters, so you should print 33.

5 3
1 2
1 4
2 3
2
100 10
1 31
2 41
1 59
2 26
1 53
2 58
1 97
2 93
1 23
2 84
69
31
6
38
38