Attendance
Time limit8sMemory limit128 MB
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 , followed by lines. An addition is given as two space-separated integers and , meaning a lecture running from to (both bounds included). Lectures are numbered in the order they are added, starting from 1. A negative number removes the lecture numbered .
Output
For every modification, output one line with the minimum number of visits required for the current schedule.
Constraints
- Every lecture number 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 and gets number 1. The next lecture added is with number 2, and it is removed immediately by the input . The following lecture added is with number 3, and so on.