#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 = 1700;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
1132 KB |
Output is correct |
2 |
Correct |
71 ms |
1244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
1840 KB |
Output is correct |
2 |
Correct |
1138 ms |
6008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
379 ms |
3108 KB |
Output is correct |
2 |
Correct |
1580 ms |
6256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
627 ms |
3488 KB |
Output is correct |
2 |
Correct |
1160 ms |
6004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1316 ms |
6064 KB |
Output is correct |
2 |
Correct |
1774 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1434 ms |
5980 KB |
Output is correct |
2 |
Correct |
1605 ms |
6108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1313 ms |
5980 KB |
Output is correct |
2 |
Correct |
2331 ms |
6884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2664 ms |
10992 KB |
Output is correct |
2 |
Correct |
1528 ms |
6136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3261 ms |
10972 KB |
Output is correct |
2 |
Correct |
3349 ms |
11004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4009 ms |
11748 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |