#abc217d. D - Cutting Woods

D - Cutting Woods

Score : 400400 points

问题描述

我们有一根长度为 LL 米的长木材。
对于每个 x=1,2,,L1x = 1, 2, \dots, L - 1,在距离木材左端 xx 米处有一个标记为 Mark xx 的记号。

你将收到 QQ 个查询请求,其中第 ii 个查询由一对数字 (ci,xi)(c_i, x_i) 表示。按照 ii 的升序依次处理这些查询,如下所述:

  • ci=1c_i = 1:在 Mark xix_i 处将木材切成两段。
  • ci=2c_i = 2:选择包含 Mark xix_i 的那段木材并输出其长度。

请注意,在处理任一类型的查询(即 ci=1c_i = 122)时,保证在处理该查询时 Mark xix_i 处尚未进行过切割。

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

5 3
2 2
1 3
2 2

Sample Output 1

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.

Sample Input 2

5 3
1 2
1 4
2 3

Sample Output 2

2

Sample Input 3

100 10
1 31
2 41
1 59
2 26
1 53
2 58
1 97
2 93
1 23
2 84

Sample Output 3

69
31
6
38
38

update @ 2024/3/10 09:36:57