#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5 + 100;
const int B = 2500;
int xl[N], yl[N], xr[N], yr[N];
bool valid[N];
bool inter(int ii, int jj){
if(xr[ii] < xl[jj] || xl[ii] > xr[jj]) return false;
if(yr[ii] < yl[jj] || yl[ii] > yr[jj]) return false;
return true;
}
bool mode;
struct Node{ // set seg, max seg
int val;
int lazy;
};
const int SZ = (int)1e6;
Node T[SZ];
void build(int node, int cl, int cr){
if(mode == false)
T[node].val = T[node].lazy = -1;
else
T[node].val = T[node].lazy = (int)1e9;
if(cl == cr){
return;
}
int mid = (cl + cr) / 2;
build(node * 2, cl, mid);
build(node * 2 + 1, mid + 1, cr);
}
void push(int node, int cl, int cr){
if(mode == false)
T[node].val = max(T[node].val, T[node].lazy);
else
T[node].val = min(T[node].val, T[node].lazy);
if(cl != cr){
if(mode == false){
T[node*2].lazy = max(T[node*2].lazy,T[node].lazy);
T[node*2+1].lazy = max(T[node*2+1].lazy,T[node].lazy);
}
else{
T[node*2].lazy = min(T[node*2].lazy,T[node].lazy);
T[node*2+1].lazy = min(T[node*2+1].lazy,T[node].lazy);
}
}
if(mode == false) T[node].lazy = -1;
else T[node].lazy = (int)1e9;
}
void update(int node, int cl, int cr, int tl, int tr, int v){
push(node, cl, cr);
if(cr < tl || cl > tr) return;
if(cl >= tl && cr <= tr){
T[node].lazy = v;
push(node, cl, cr);
return;
}
int mid = (cl + cr) / 2;
update(node * 2, cl, mid, tl, tr, v);
update(node * 2 + 1, mid + 1, cr, tl, tr, v);
if(mode == false)
T[node].val = max(T[node*2].val, T[node*2+1].val);
else
T[node].val = min(T[node*2].val, T[node*2+1].val);
}
int get(int node, int cl, int cr, int tl, int tr){
push(node, cl, cr);
if(cr < tl || cl > tr){
if(mode == false) return -1;
else return (int)1e9;
}
if(cl >= tl && cr <= tr){
return T[node].val;
}
int mid = (cl + cr) / 2;
if(mode == false)
return max(get(node*2,cl,mid,tl,tr),get(node*2+1,mid+1,cr,tl,tr));
else
return min(get(node*2,cl,mid,tl,tr),get(node*2+1,mid+1,cr,tl,tr));
}
struct Eve{
int type;
int xl;
int yl;
int xr;
int yr;
int idx;
bool operator<(const Eve &R){
if(mode == false){
if(xr == R.xr){
return type < R.type; // 0 - updates 1 - queries
}
return xl < R.xl;
}
else{
if(xl == R.xl) {
return type < R.type;
}
return xl > R.xl;
}
}
};
int main(){
fastIO;
int n;
cin >> n;
vector<int> xx, yy;
for(int i = 0 ; i < n; i ++ ){
cin >> xl[i] >> yl[i] >> xr[i] >> yr[i];
xr[i] += xl[i]-1;
yr[i] += yl[i]-1;
xx.push_back(xl[i]);
xx.push_back(xr[i]);
yy.push_back(yl[i]);
yy.push_back(yr[i]);
valid[i]=true;
}
sort(xx.begin(), xx.end());
sort(yy.begin(), yy.end());
xx.resize(unique(xx.begin(), xx.end()) - xx.begin());
yy.resize(unique(yy.begin(), yy.end()) - yy.begin());
for(int i = 0 ; i < n; i ++ ){
xl[i] = lower_bound(xx.begin(), xx.end(), xl[i]) - xx.begin();
yl[i] = lower_bound(yy.begin(), yy.end(), yl[i]) - yy.begin();
xr[i] = lower_bound(xx.begin(), xx.end(), xr[i]) - xx.begin();
yr[i] = lower_bound(yy.begin(), yy.end(), yr[i]) - yy.begin();
}
int m = yy.size();
vector<int> ids;
vector<Eve> shas;
int wap;
for(int i = n - 1; i >= 0 ; i -- ){
for(auto x : ids){
if(inter(i,x)){
valid[i]=false;
}
}
ids.push_back(i);
if(ids.size() == B || i == 0){
for(auto x : ids){
shas.push_back({1, xl[x], yl[x], xr[x], yr[x], x});
}
mode=false;
sort(shas.begin(), shas.end());
build(1, 0, m - 1);
for(auto x : shas){
if(x.type == 0){
update(1, 0, m - 1, x.yl, x.yr, x.xr);
}
else{
wap = get(1, 0, m - 1, x.yl, x.yr);
if(wap >= x.xl){
valid[x.idx]=false;
}
}
}
mode = true;
sort(shas.begin(), shas.end());
build(1, 0, m - 1);
for(auto x : shas){
if(x.type == 0){
update(1, 0, m - 1, x.yl, x.yr, x.xl);
}
else{
wap = get(1, 0, m - 1, x.yl, x.yr);
if(wap <= x.xr){
valid[x.idx]=false;
}
}
}
for(auto &x : shas){
x.type = 0;
}
ids.clear();
}
}
for(int i = 0 ; i < n; i ++ ){
if(valid[i]) cout << "DA\n";
else cout << "NE\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
1132 KB |
Output is correct |
2 |
Correct |
78 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
1976 KB |
Output is correct |
2 |
Correct |
992 ms |
5896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
374 ms |
3108 KB |
Output is correct |
2 |
Correct |
1374 ms |
6236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
616 ms |
3488 KB |
Output is correct |
2 |
Correct |
1018 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1157 ms |
6032 KB |
Output is correct |
2 |
Correct |
1536 ms |
6376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1333 ms |
5980 KB |
Output is correct |
2 |
Correct |
1428 ms |
6376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1137 ms |
6108 KB |
Output is correct |
2 |
Correct |
1935 ms |
6764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2259 ms |
10708 KB |
Output is correct |
2 |
Correct |
1328 ms |
8004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2675 ms |
11116 KB |
Output is correct |
2 |
Correct |
2621 ms |
13632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4035 ms |
11704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |