-
Notifications
You must be signed in to change notification settings - Fork 0
/
E1.cpp
109 lines (103 loc) · 1.92 KB
/
E1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "bits/stdc++.h"
using namespace std;
int l[100010], r[100010];
int u[100010], d[100010];
int suf[100010];
bool mark[100010];
int n;
const int inf = 1e9 + 7;
bool solve(vector <int> &rs, vector <int> &ds) {
int sz = rs.size();
if(sz == 1) return true;
suf[sz] = inf;
for(int i = sz - 1; i >= 0; i--) {
suf[i] = min(suf[i + 1], l[rs[i]]);
}
for(int i = 0; i < sz - 1; i++) {
if(r[rs[i]] <= suf[i + 1]) {
for(int j = 0; j <= n; j++) {
mark[j] = false;
}
vector <int> p, q;
vector <int> x, y;
for(int j = 0; j <= i; j++) {
mark[rs[j]] = true;
}
for(int j : rs) {
if(mark[j]) {
p.push_back(j);
} else {
q.push_back(j);
}
}
for(int j : ds) {
if(mark[j]) {
x.push_back(j);
} else {
y.push_back(j);
}
}
rs.clear();
ds.clear();
return solve(p, x) && solve(q, y);
}
}
suf[sz] = inf;
for(int i = sz - 1; i >= 0; i--) {
suf[i] = min(suf[i + 1], u[ds[i]]);
}
for(int i = 0; i < sz - 1; i++) {
if(d[ds[i]] <= suf[i + 1]) {
for(int j = 0; j <= n; j++) {
mark[j] = false;
}
vector <int> p, q;
vector <int> x, y;
for(int j = 0; j <= i; j++) {
mark[ds[j]] = true;
}
for(int j : rs) {
if(mark[j]) {
p.push_back(j);
} else {
q.push_back(j);
}
}
for(int j : ds) {
if(mark[j]) {
x.push_back(j);
} else {
y.push_back(j);
}
}
rs.clear();
ds.clear();
return solve(p, x) && solve(q, y);
}
}
return false;
}
bool cmp1(int i, int j) {
return r[i] < r[j];
}
bool cmp2(int i, int j) {
return d[i] < d[j];
}
int main(int argc, char const *argv[])
{
scanf("%d", &n);
vector <int> rs, ds;
for(int i = 1; i <= n; i++) {
scanf("%d %d %d %d", l + i, u + i, r + i, d + i);
rs.push_back(i);
ds.push_back(i);
}
sort(rs.begin(), rs.end(), cmp1);
sort(ds.begin(), ds.end(), cmp2);
if(solve(rs, ds)) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}