PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000238. Lịch đặt chỗ (My Calendar I)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Lịch đặt chỗ (My Calendar I)
My Calendar I
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
The calendar starts empty. Request reserves the half-open interval , including its start but excluding its end. Accept a request and store its interval exactly when it shares no time with an already accepted event. Rejecting a request leaves the calendar unchanged. Intervals touching only at an endpoint do not overlap. Process the requests in order.
Input
The first line contains integer . Each of the next lines contains integers , the start and end of request .
Output
Print lines in request order: YES for acceptance, NO for rejection.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for all ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
4
10 20
15 25
20 30
0 10
Output
YES
NO
YES
YES
Explanation
Store . Reject because the intersection is . Both and only touch endpoints of stored events, so accept them.