All problems

Problem 692

My Calendar III

Hard · 30 pts · Design, Sweep Line, Segment Tree

Problem

Bookings are half-open intervals [start, end) and every booking is accepted, even if it overlaps others. A K-booking happens when K bookings share some common moment. After each booking, print the largest K such that a K-booking exists among all bookings so far. Keep a sorted map of +1 at each start and -1 at each end; the maximum running sum over the map is the answer. With at most 400 bookings, re-sweeping after every booking is fast enough.

Input

The first line contains N. Each of the next N lines contains start and end of a booking.

Output

Print N integers, one per line: the largest K after each booking.

Constraints

1 <= N <= 400; 0 <= start < end <= 10^9

Example input

6
10 20
50 60
10 40
5 15
5 10
25 55

Example output

1
1
2
3
3
3

Explanation

After [10,20) and [50,60) no two bookings overlap, so K is 1. [10,40) overlaps the first, so K becomes 2. [5,15) overlaps both [10,20) and [10,40) at time 10, so K becomes 3.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: My Calendar I Next: Snapshot Array