102173: [AtCoder]ABC217 D - Cutting Woods

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $400$ points

Problem Statement

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.

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.

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$

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.


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 $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$.


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

Input

题意翻译

给定一个长度为 $L$ 的序列 $[1,L]$ 和 $q$ 个询问。对于第 $i$ 次询问有一个 $c_i$ 和 $x_i$,如果 $c_i=1$,将 $x$ 点所在的区间 $[l,r]$ 分为 $[l,x]$ 和 $[x+1,r]$;如果 $c_i=2$,输出 $x$ 点所在区间的长度。

Output

得分:$400$分

问题描述

我们有一根长为$L$米的木头。对于每个$x = 1, 2, \dots, L - 1$,在距离木头左端$x$米的地方有一个标记,称为标记$x$。

给你$Q$个查询,其中第$i$个查询表示为一个数字对$(c_i, x_i)$。

  • 如果$c_i = 1$:在标记$x_i$处将木头切成两段。
  • 如果$c_i = 2$:选择带有标记$x_i$的木头段并输出其长度。

在这里,对于两种类型的查询$c_i = 1, 2$,都保证在处理查询时,木头在标记$x_i$处不会有切口。

约束

  • $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)$
  • 对于每个$i$ $(1 \leq i \leq Q)$,以下条件成立:没有$j$满足$1 \leq j \lt i$和$(c_j,x_j) = (1, x_i)$。
  • 输入中的所有值都是整数。

输入

从标准输入按以下格式给出输入:

$L$ $Q$
$c_1$ $x_1$
$c_2$ $x_2$
$\vdots$
$c_Q$ $x_Q$

输出

输出等于查询$c_i = 2$的数量的行数。在第$j$行中,输出对第$j$个此类查询的响应。


样例输入1

5 3
2 2
1 3
2 2

样例输出1

5
3

在第一次查询时,还没有进行过切割,所以带有标记$2$的木头段长为$5$米。因此,你应该输出$5$。
在第二次查询时,木头被切成了长度为$3$和$2$米的两段。
在第三次查询时,带有标记$2$的木头段长为$3$米,所以你应该输出$3$。


样例输入2

5 3
1 2
1 4
2 3

样例输出2

2

样例输入3

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

样例输出3

69
31
6
38
38

加入题单

上一题 下一题 算法标签: