This page is still under construction.

Parts of this page are still being built. What you see may change.

New Year and Conference

Time limit2sMemory limit1024 MB

Summary
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 nn lectures. Hyunuk has two candidate venues aa and bb. For each of the nn lectures, the speaker specified two time intervals [sai,eai][sa_i, ea_i] (sai≤eaisa_i \le ea_i) and [sbi,ebi][sb_i, eb_i] (sbi≤ebisb_i \le eb_i). If the conference is situated in venue aa, the lecture will be held from saisa_i to eaiea_i, and if the conference is situated in venue bb, the lecture will be held from sbisb_i to ebieb_i. 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 [x,y][x, y] overlaps with a lecture held in interval [u,v][u, v] if and only if max⁡(x,u)≤min⁡(y,v)\max(x, u) \le \min(y, v).

We say that a participant can attend a subset ss of the lectures if the lectures in ss do not pairwise overlap (i.e. no two lectures overlap). Note that the possibility of attending may depend on whether Hyunuk selected venue aa or venue bb to hold the conference.

A subset of lectures ss is said to be venue-sensitive if, for one of the venues, the participant can attend ss, but for the other venue, the participant cannot attend ss.

A venue-sensitive set is problematic for a participant who is interested in attending the lectures in ss 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 nn (1≤n≤100 0001 \le n \le 100\,000), the number of lectures held in the conference.

Each of the next nn lines contains four integers saisa_i, eaiea_i, sbisb_i, ebieb_i (1≤sai,eai,sbi,ebi≤1091 \le sa_i, ea_i, sb_i, eb_i \le 10^9, sai≤eaisa_i \le ea_i, sbi≤ebisb_i \le eb_i).

Output

Print "YES" if Hyunuk will be happy. Print "NO" otherwise.

Notes

In the second example, lecture set {1,3}\{1, 3\} is venue-sensitive. Because the participant cannot attend these lectures in venue aa, but can attend in venue bb.

In the first and third examples, no venue-sensitive set exists.

Examples3

  1. Example 1

    Input
    2
    1 2 3 6
    3 4 7 8
    
    Expected output
    YES
    
  2. Example 2

    Input
    3
    1 3 2 4
    4 5 6 7
    3 4 5 5
    
    Expected output
    NO
    
  3. Example 3

    Input
    6
    1 5 2 9
    2 4 5 8
    3 6 7 11
    7 10 12 16
    8 11 13 17
    9 12 14 18
    
    Expected output
    YES