#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define taskname "SUMCANJE"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 1e5 + 1;
const int INF = 1e9;
struct rectangle{
int x1, x2, y1, y2;
rectangle(int _x1 = 0, int _x2 = 0, int _y1 = 0, int _y2 = 0){
x1 = _x1;
x2 = _x2;
y1 = _y1;
y2 = _y2;
}
};
struct segmentTree{
set <ii> d0[N * 8], d1[N * 8]; /// 0 : inSide, 1 : outside
bool check(set <ii> &s, int l, int r){
if (s.empty())
return 1;
auto it = s.lower_bound(mp(l, 0));
if (it != s.end()){
if ((*it).X <= r)
return 0;
}
if (it != s.begin()){
--it;
if ((*it).Y >= l)
return 0;
}
return 1;
}
void add(set <ii> &s, int l, int r){
if (s.empty()){
s.insert(mp(l, r));
return;
}
auto first = s.upper_bound(mp(l, 0));
auto last = s.upper_bound(mp(r, INF));
if (first != s.begin()){
--first;
if ((*first).Y < l)
++first;
}
vector <ii> tmp;
while (first != last){
tmp.push_back(*first);
++first;
}
for(ii p : tmp){
s.erase(p);
l = min(l, p.X);
r = max(r, p.Y);
}
s.insert(mp(l, r));
}
bool addRect(int id, int l, int r, int x1, int x2, int y1, int y2){
if (x2 < l || r < x1)
return 1;
bool res = check(d1[id], y1, y2);
if (x1 <= l && r <= x2){
res = res && check(d0[id], y1, y2);
add(d0[id], y1, y2);
add(d1[id], y1, y2);
return res;
}
add(d0[id], y1, y2);
int mid = (l + r) >> 1;
res &= addRect(id << 1, l, mid, x1, x2, y1, y2);
res &= addRect(id << 1 | 1, mid + 1, r, x1, x2, y1, y2);
return res;
}
} ST;
int n;
rectangle rect[N];
int x[2 * N], nX, y[2 * N], nY;
bool ans[N];
void readInput(){
cin >> n;
for(int i = 1; i <= n; i++){
int x, y, a, b;
cin >> x >> y >> a >> b;
rect[i] = rectangle(x, x + a - 1, y, y + b - 1);
}
}
void prepare(){
for(int i = 1; i <= n; i++){
x[++nX] = rect[i].x1;
x[++nX] = rect[i].x2;
y[++nY] = rect[i].y1;
y[++nY] = rect[i].y2;
}
sort(x + 1, x + 1 + nX);
sort(y + 1, y + 1 + nY);
nX = unique(x + 1, x + 1 + nX) - (x + 1);
nY = unique(y + 1, y + 1 + nY) - (y + 1);
for(int i = 1; i <= n; i++){
rect[i].x1 = lower_bound(x + 1, x + 1 + nX, rect[i].x1) - x;
rect[i].x2 = lower_bound(x + 1, x + 1 + nX, rect[i].x2) - x;
rect[i].y1 = lower_bound(y + 1, y + 1 + nY, rect[i].y1) - y;
rect[i].y2 = lower_bound(y + 1, y + 1 + nY, rect[i].y2) - y;
}
}
void solve(){
for(int i = n; i >= 1; i--)
ans[i] = ST.addRect(1, 1, nX, rect[i].x1, rect[i].x2, rect[i].y1, rect[i].y2);
for(int i = 1; i <= n; i++)
if (ans[i])
cout << "DA\n";
else
cout << "NE\n";
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen(taskname".inp", "r", stdin);
//freopen(taskname".out", "w", stdout);
readInput();
prepare();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
80376 KB |
Output is correct |
2 |
Correct |
112 ms |
81784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
247 ms |
84984 KB |
Output is correct |
2 |
Correct |
878 ms |
116256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
428 ms |
90680 KB |
Output is correct |
2 |
Correct |
1156 ms |
128888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
549 ms |
96888 KB |
Output is correct |
2 |
Correct |
989 ms |
121340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1040 ms |
116064 KB |
Output is correct |
2 |
Correct |
1217 ms |
130040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
988 ms |
112760 KB |
Output is correct |
2 |
Correct |
1271 ms |
130948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1030 ms |
124664 KB |
Output is correct |
2 |
Correct |
1198 ms |
116796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1562 ms |
149168 KB |
Output is correct |
2 |
Correct |
957 ms |
111480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1739 ms |
146612 KB |
Output is correct |
2 |
Correct |
1812 ms |
155640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1959 ms |
149240 KB |
Output is correct |
2 |
Correct |
2324 ms |
175072 KB |
Output is correct |