All problems

Problem 691

My Calendar I

Medium · 20 pts · Design, Binary Search, Ordered Set

Problem

Implement a calendar that accepts bookings without double booking. A booking is a half-open interval [start, end), so a booking ending at 10 and one starting at 10 do not overlap. For each requested booking, in order, print true and add it to the calendar if it does not overlap any accepted booking; otherwise print false and ignore it. Two bookings [s1, e1) and [s2, e2) overlap exactly when s1 < e2 and s2 < e1.

Input

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

Output

Print true or false for each request, one per line.

Constraints

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

Example input

3
10 20
15 25
20 30

Example output

true
false
true

Explanation

The booking [10,20) is accepted. [15,25) overlaps it, so it is rejected. [20,30) starts exactly when the first one ends, so it is accepted. The output is true, false, true.

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

Previous: Range Frequency Queries Next: My Calendar III