Under construction

Still being built. Things may change

Attendance

Time limit8sMemory limit128 MB

Summary
After each insertion or removal of an interval, print the minimum number of points needed so that every interval on the current list contains at least one point.
Level

Hard8 of 10

Topics
Intervals, Greedy, Segment tree
Solved
No attempts yet

Problem

An ambitious university student has enrolled in almost every course offered. Unfortunately, every course requires mandatory attendance. He visits the campus several times a day. On each visit, he joins every lecture running at that moment, signs its attendance sheet, and leaves right away for his other obligations. He returns later that day to repeat the process for the lectures he has not yet signed, and continues until his name is on the attendance sheet of every lecture.

The lecture schedule keeps changing, though. Lectures are added and canceled, so the student must keep adjusting his visiting schedule to sign the attendance sheets of all lectures.

The schedule starts empty. Read the modifications one at a time, each adding or removing a single lecture. After each modification, output the minimum number of visits the student needs to sign the attendance sheets of all lectures currently on the schedule.

Input

The first line contains the number of modifications NN, followed by NN lines. An addition is given as two space-separated integers AiA_i and BiB_i, meaning a lecture running from AiA_i to BiB_i (both bounds included). Lectures are numbered in the order they are added, starting from 1. A negative number XiX_i removes the lecture numbered −Xi-X_i.

Output

For every modification, output one line with the minimum number of visits required for the current schedule.

Constraints

  • 1≤N≤300 0001 \leq N \leq 300\,000
  • 0≤Ai≤Bi≤1090 \leq A_i \leq B_i \leq 10^9
  • Every lecture number XiX_i to be removed is valid. It exists in the schedule at that moment.
  • Pay attention to the memory limit.

Hint

The first lecture added is [2,2][2, 2] and gets number 1. The next lecture added is [17,26][17, 26] with number 2, and it is removed immediately by the input −2-2. The following lecture added is [12,21][12, 21] with number 3, and so on.

Examples1

  1. Example 1

    Input
    12
    2 2
    17 26
    -2
    12 21
    0 0
    19 21
    16 22
    14 20
    15 19
    13 14
    -4
    13 17
    
    Expected output
    1
    2
    1
    2
    3
    3
    3
    3
    3
    4
    3
    3