#P14705. [ICPC 2023 Tehran R] Moderation in all things

[ICPC 2023 Tehran R] Moderation in all things

题目描述

Initially, we have an array of length 1 containing only the number 0. All natural numbers are listed in ascending order in the "reservation list" (the first number in the list is 1). The array undergoes qq operations. The ithi^{th} operation, is one of the following:

  • Insert(p,x)(p, x): Insert the first xx numbers from the reservation list after the number pp in the array, in ascending order. These numbers are removed from the reservation list.
  • Remove(p,x)(p, x): Remove the next xx numbers after number pp in the array. These numbers are not returned to the reservation list.

You are given information about qq operations, and you are asked to determine the number written in the middle of the array after each operation. If the length of the array after the ithi^{th} operation is nn, you should find the n2th\left\lfloor \frac{n}{2} \right\rfloor^{th} element of the array. Note that the indexing of the array starts from 1.

输入格式

The first line contains an integer qq (1q51051 \leq q \leq 5 \cdot 10^5), which represents the number of operations. Each of the next qq lines contains two integers: pip_i (1pi21091 \leq p_i \leq 2 \cdot 10^9), and kik_i (1ki21091 \leq |k_i| \leq 2 \cdot 10^9).

If ki=+xk_i = +x, operation Insert(pi,x)(p_i, x) is executed. If ki=xk_i = -x, operation Remove(pi,x)(p_i, x) is executed. It is guaranteed that all operations are valid, and no impossible operation is performed on the array. Additionally, at most 21092 \cdot 10^9 numbers are moved from the reservation list into the array.

输出格式

Output qq lines. In the ithi^{th} line, print the middle element of the array after performing the ithi^{th} operation.

10
0 3
0 2
5 -2
4 1
0 -2
5 2
7 3
3 2
10 5
12 20
1
5
4
6
5
7
9
10
16
22