New Year and Conference
Time limit2sMemory limit1024 MB
Given n lectures, each with one time interval at venue a and another at venue b, decide whether every subset that is conflict-free at one venue is also conflict-free at the other.
- Level
Hard8 of 10
- Topics
- Intervals, Sorting, Prefix sum, Binary search
- Solved
- No attempts yet
Problem
Filled with optimism, Hyunuk will host a conference about how great this new year will be!
The conference will have lectures. Hyunuk has two candidate venues and . For each of the lectures, the speaker specified two time intervals () and (). If the conference is situated in venue , the lecture will be held from to , and if the conference is situated in venue , the lecture will be held from to . Hyunuk will choose one of these venues and all lectures will be held at that venue.
Two lectures are said to overlap if they share any point in time in common. Formally, a lecture held in interval overlaps with a lecture held in interval if and only if .
We say that a participant can attend a subset of the lectures if the lectures in do not pairwise overlap (i.e. no two lectures overlap). Note that the possibility of attending may depend on whether Hyunuk selected venue or venue to hold the conference.
A subset of lectures is said to be venue-sensitive if, for one of the venues, the participant can attend , but for the other venue, the participant cannot attend .
A venue-sensitive set is problematic for a participant who is interested in attending the lectures in because the participant cannot be sure whether the lecture times will overlap. Hyunuk will be happy if and only if there are no venue-sensitive sets. Determine whether Hyunuk will be happy.
Input
The first line contains an integer (), the number of lectures held in the conference.
Each of the next lines contains four integers , , , (, , ).
Output
Print "YES" if Hyunuk will be happy. Print "NO" otherwise.
Notes
In the second example, lecture set is venue-sensitive. Because the participant cannot attend these lectures in venue , but can attend in venue .
In the first and third examples, no venue-sensitive set exists.