Moderation in all things | 프로그래밍의 벗 PivotOJ
PivotOJ

Moderation in all things

시간 제한: 1000ms메모리 제한: 2048MB출처: ICPC Asia Tehran Regional Contest 2023BOJ 33180

문제

Initially, we have an array of length 11 containing only the number 00. All natural numbers are listed in ascending order in the “reservation list” (the first number in the list is 11). The array undergoes qq operations. The iith operation, is one of the following:

  • Insert(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): 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 iith operation is nn, you should find the n2\lceil \frac{n} {2} \rceilth element of the array. Note that the indexing of the array starts from 11.

입력

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

If ki=+xk_i = +x, operation Insert(pi, x) is executed. If ki=xk_i = -x, operation Remove(pi, 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 iith line, print the middle element of the array after performing the iith operation.

예제

예제 1

입력
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
코드를 제출하려면 로그인하세요.