#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;
};
Node T[N * 4 + 512];
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 |
59 ms |
1372 KB |
Output is correct |
2 |
Correct |
81 ms |
1500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
2292 KB |
Output is correct |
2 |
Correct |
956 ms |
7232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
369 ms |
3876 KB |
Output is correct |
2 |
Correct |
1405 ms |
8028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
606 ms |
4804 KB |
Output is correct |
2 |
Correct |
1034 ms |
7388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1206 ms |
7516 KB |
Output is correct |
2 |
Correct |
1573 ms |
8308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1290 ms |
7772 KB |
Output is correct |
2 |
Correct |
1435 ms |
7944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1147 ms |
7772 KB |
Output is correct |
2 |
Correct |
1929 ms |
9196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2173 ms |
12548 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2403 ms |
12760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2987 ms |
13760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |