#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PB push_back
#define all(x) x.begin(),x.end()
#define pii pair<int,unsigned short>
#define MP make_pair
#define ft first
#define sd second
#define sz(x) ((int)x.size())
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
const int N = 100100;
const int PW = 22;
const int oo = 2e9;
vector<int> xs, ys;
bool mrk[N];
int x1[N], Y1[N], x2[N], y2[N], n, IND;
ordered_set<pii> up, down, Left, Right, st[4][N];
int get_up_left(int x, int y){
int res = 0;
for (int v = x; v >= 0; v = (v & (v + 1)) - 1)
res += sz(st[0][v]) - st[0][v].order_of_key(MP(y - 1, oo));
return res;
}
int get_down_left(int x, int y){
int res = 0;
for (int v = x; v >= 0; v = (v & (v + 1)) - 1)
res += st[2][v].order_of_key(MP(y, oo));
return res;
}
int get_up_right(int x, int y){
int res = 0;
for (int v = x; v >= 0; v = (v & (v + 1)) - 1)
res += sz(st[1][v]) - st[1][v].order_of_key(MP(y - 1, oo));
return res;
}
int get_down_right(int x, int y){
int res = 0;
for (int v = x; v >= 0; v = (v & (v + 1)) - 1)
res += st[3][v].order_of_key(MP(y, oo));
return res;
}
void update_fi(int tp, int x, int y){
for (int v = x; v < sz(xs); v = (v | (v + 1)))
st[tp][v].insert(MP(y, IND));
}
void update_se(int tp, int x, int y){
for (int v = x; v < sz(xs); v = (v | (v + 1)))
st[tp][v].insert(MP(y, IND));
}
// ses
void update_fis(int tp, int x, int y){
for (int v = x; v < sz(ys); v = (v | (v + 1)))
st[tp][v].insert(MP(y, IND));}
void update_ses(int tp, int x, int y){
for (int v = x; v < sz(ys); v = (v | (v + 1)))
st[tp][v].insert(MP(y, IND));
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n;
for (int i = 0; i < n; i++){
int X, Y; cin >> x1[i] >> Y1[i] >> X >> Y;
x2[i] = x1[i] + X;
y2[i] = Y1[i] + Y;
xs.PB(x1[i]);
ys.PB(x2[i]);
}
sort(all(xs));
sort(all(ys));
xs.resize(unique(all(xs)) - xs.begin());
ys.resize(unique(all(ys)) - ys.begin());
up.clear();
down.clear();
Left.clear();
Right.clear();
for (int i = n - 1; i >= 0; i--){
if (i < n - 1){
int kol = 0;
kol += sz(up) - up.order_of_key(MP(y2[i] - 1, oo));
kol += Left.order_of_key(MP(x1[i], oo));
kol += down.order_of_key(MP(Y1[i], oo));
kol += sz(Right) - Right.order_of_key(MP(x2[i] - 1, oo));
int loc = upper_bound(all(ys), x1[i]) - ys.begin() - 1;
kol -= get_up_left(loc, y2[i]);
loc = upper_bound(all(ys), x1[i]) - ys.begin() - 1;
kol -= get_down_left(loc, Y1[i]);
loc = lower_bound(all(xs), x2[i]) - xs.begin();
kol -= get_up_right(sz(xs) - 1 - loc, y2[i]);
loc = lower_bound(all(xs), x2[i]) - xs.begin();
kol -= get_down_right(sz(xs) - 1 - loc, Y1[i]);
if (kol < n - i - 1)
mrk[i] = 1;
}
// add new elements
up.insert(MP(Y1[i], i));
down.insert(MP(y2[i], i));
Left.insert(MP(x2[i], i));
Right.insert(MP(x1[i], i));
IND = i;
int loc = lower_bound(all(ys), x2[i]) - ys.begin();
update_fis(2, loc, y2[i]);
loc = lower_bound(all(xs), x1[i]) - xs.begin();
update_fi(3, sz(xs) - 1 - loc, y2[i]);
loc = lower_bound(all(ys), x2[i]) - ys.begin();
update_ses(0, loc, Y1[i]);
loc = lower_bound(all(xs), x1[i]) - xs.begin();
update_se(1, sz(xs) - 1 - loc, Y1[i]);
}
for (int i = 0; i < n; i++)
cout << (mrk[i] ? "NE\n" : "DA\n");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
173 ms |
47864 KB |
Output is correct |
2 |
Correct |
216 ms |
51960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
456 ms |
64248 KB |
Output is correct |
2 |
Correct |
2309 ms |
141684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1010 ms |
87032 KB |
Output is correct |
2 |
Incorrect |
3045 ms |
166428 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1548 ms |
106644 KB |
Output is correct |
2 |
Correct |
2431 ms |
145400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2609 ms |
150132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2895 ms |
157004 KB |
Output is correct |
2 |
Incorrect |
3210 ms |
167188 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2846 ms |
156148 KB |
Output is correct |
2 |
Correct |
3947 ms |
187280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4089 ms |
208704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4086 ms |
195960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4110 ms |
203876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |