Moderation in all things

시간 제한1초메모리 제한2048 MB

요약
가장 작은 미사용 양의 정수를 삽입하거나 일부를 제거하면서, 매 연산 뒤 배열의 가운데 원소를 출력한다.
난이도

어려움10점 중 9점

유형
트리, 구현, 이분 탐색, 수학
정답자
아직 제출이 없습니다

문제

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 (1≤q≤5⋅1051 \le q \le 5 \cdot 10^5), which represents the number of operations. Each of the next qq lines contains two integers: p_ip\_i (1≤p_i≤2⋅1091 \le p\_i \le 2 \cdot 10^9), and k_ik\_i (1≤∣k_i∣≤2⋅1091 \le |k\_i | \le 2 \cdot 10^9).

If k_i=+xk\_i = +x, operation Insert(pi, x) is executed. If k_i=−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 2⋅1092 \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

  1. 예제 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