Attendance

시간 제한8초메모리 제한128 MB

요약
닫힌 구간으로 주어지는 강의가 하나씩 추가되거나 삭제될 때마다, 현재 모든 강의를 덮는 최소 개수의 시각을 출력한다.
난이도

어려움10점 중 8점

유형
그리디, 구간, 정렬, 세그먼트 트리
정답자
아직 제출이 없습니다

문제

An ambitious university student has enrolled in just about every possible course. Unfortunately, the courses require mandatory attendance. He has decided to visit the university campus where the lectures are held several times a day. He will join every lecture that is running at that moment, sign the attendance sheet, and immediately leave the campus due to other obligations. He will return later that day, when he will repeat this process to sign attendance sheets at other lectures and so on until his name is on attendance sheets of all lectures.

As if this was not problematic enough, the student faces another obstacle: the schedule of the lectures keeps changing. Some lectures are added and some are canceled. The student has to keep adjusting his visiting schedule of the university to sign attendance sheets at all lectures.

Write a program that will start with an empty schedule of lectures and read sequential modifications, which are either an addition or removal of a single lecture. For every modification, output the minimum number of visits that the student has to make to sign attendance sheets at all lectures that are currently on the schedule.

입력

The first line contains the number of modifications NN, which are given in the following NN lines. An addition of a lecture is described with two space-separated integers A_iA\_i and B_iB\_i, which represent a lecture that is running from A_iA\_i to B_iB\_i (including both bounds). The lectures are numbered as they are added, sequentially from 11 onwards. A negative number X_iX\_i represents a removal of lecture with the number ,−X_i\\,{-X\_i}.

출력

For every modification output a single line with the minimum number of required visits for the current schedule of lectures.

제한

  • 1≤N≤300,0001 \leq N \leq 300\\,000
  • 0≤A_i≤B_i≤1090 \leq A\_i \leq B\_i \leq 10^9
  • Every number of the lecture for removal X_iX\_i will be valid – it will exist in the schedule at that moment.
  • Note the memory limit.

힌트

The first lecture to be added is \[2,2]\[2, 2] and is given number 11. Next added lecture is \[17,26]\[17, 26] with number 22. It is removed immediately afterwards, which is indicated by −2-2 in the input. The following added lecture is \[12,21]\[12, 21], which is given number 33 and so on.

예제1

  1. 예제 1

    입력
    12
    2 2
    17 26
    -2
    12 21
    0 0
    19 21
    16 22
    14 20
    15 19
    13 14
    -4
    13 17
    
    예상 출력
    1
    2
    1
    2
    3
    3
    3
    3
    3
    4
    3
    3