/* Ivan Carvalho
O(N*log(N)^2)
Note that this codes simulates a 2d Segment Tree using only one segment tree.
*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii; // idx and type
const int MAXN = 2*1e5 + 10;
struct node{
int seg[4*MAXN][2];
void update(int pos,int left,int right,int i,int j,int iteration){
if(left >= i && right <= j){
seg[pos][0] = iteration;
seg[pos][1] = iteration;
return;
}
int mid = (left+right)/2;
seg[pos][0] = iteration;
if(j <= mid){
update(2*pos,left,mid,i,j,iteration);
}
else if(i >= mid + 1){
update(2*pos+1,mid+1,right,i,j,iteration);
}
else{
update(2*pos,left,mid,i,j,iteration);
update(2*pos+1,mid+1,right,i,j,iteration);
}
}
bool query(int pos,int left,int right,int i,int j,int iteration){
if(left >= i && right <= j) return seg[pos][0] == iteration;
if(seg[pos][1] == iteration) return true;
int mid = (left+right)/2;
if(j <= mid) return query(2*pos,left,mid,i,j,iteration);
else if(i >= mid + 1) return query(2*pos+1,mid+1,right,i,j,iteration);
else return query(2*pos,left,mid,i,j,iteration) || query(2*pos+1,mid+1,right,i,j,iteration);
}
};
vector<int> compx,compy;
vector<ii> offline_trick[4*MAXN];
bool isCovered[MAXN];
int N,szY,szX,X1[MAXN],X2[MAXN],Y1[MAXN],Y2[MAXN],cur_iteration;
node seg_all,seg_some;
void build_tree(int pos,int left,int right,int ix,int jx,int idx){
// Interval is contained
if(left >= ix && right <= jx){
offline_trick[pos].push_back(ii(idx,1));
return;
}
int mid = (left+right)/2;
offline_trick[pos].push_back(ii(idx,0));
if(jx <= mid){
build_tree(2*pos,left,mid,ix,jx,idx);
}
else if(ix >= mid + 1){
build_tree(2*pos+1,mid+1,right,ix,jx,idx);
}
else{
build_tree(2*pos,left,mid,ix,jx,idx);
build_tree(2*pos+1,mid+1,right,ix,jx,idx);
}
}
void process_node(int segPos){
cur_iteration++;
for(ii u : offline_trick[segPos]){
int idx = u.first, which_type = u.second;
int y1 = Y1[idx],y2 = Y2[idx] - 1;
if(which_type == 0){
isCovered[idx] |= seg_all.query(1,1,szY,y1,y2,cur_iteration);
seg_some.update(1,1,szY,y1,y2,cur_iteration);
}
else{
isCovered[idx] |= seg_some.query(1,1,szY,y1,y2,cur_iteration);
seg_some.update(1,1,szY,y1,y2,cur_iteration);
seg_all.update(1,1,szY,y1,y2,cur_iteration);
}
}
}
int main(){
scanf("%d",&N);
for(int i = 1;i<=N;i++){
int xi,yi,ai,bi;
scanf("%d %d %d %d",&xi,&yi,&ai,&bi);
X1[i] = xi;
X2[i] = xi + ai;
Y1[i] = yi;
Y2[i] = yi + bi;
compx.push_back(X1[i]);
compx.push_back(X2[i]);
compy.push_back(Y1[i]);
compy.push_back(Y2[i]);
}
sort(compx.begin(),compx.end());
compx.erase(unique(compx.begin(),compx.end()),compx.end());
sort(compy.begin(),compy.end());
compy.erase(unique(compy.begin(),compy.end()),compy.end());
szY = (int)compy.size();
szX = (int)compx.size();
for(int i = 1;i<=N;i++){
X1[i] = lower_bound(compx.begin(),compx.end(),X1[i]) - compx.begin() + 1;
X2[i] = lower_bound(compx.begin(),compx.end(),X2[i]) - compx.begin() + 1;
Y1[i] = lower_bound(compy.begin(),compy.end(),Y1[i]) - compy.begin() + 1;
Y2[i] = lower_bound(compy.begin(),compy.end(),Y2[i]) - compy.begin() + 1;
}
for(int i = N;i>=1;i--){
build_tree(1,1,szX,X1[i],X2[i]-1,i);
}
for(int i = 1;i<=4*szX;i++) process_node(i);
for(int i = 1;i<=N;i++){
if(isCovered[i]) printf("NE\n");
else printf("DA\n");
}
return 0;
}
Compilation message
suncanje.cpp: In function 'int main()':
suncanje.cpp:106:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&N);
~~~~~^~~~~~~~~
suncanje.cpp:109:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d",&xi,&yi,&ai,&bi);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
21240 KB |
Output is correct |
2 |
Correct |
87 ms |
22248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
25428 KB |
Output is correct |
2 |
Correct |
694 ms |
39516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
345 ms |
39516 KB |
Output is correct |
2 |
Correct |
859 ms |
43448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
497 ms |
43448 KB |
Output is correct |
2 |
Correct |
678 ms |
43448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
886 ms |
43448 KB |
Output is correct |
2 |
Correct |
984 ms |
45420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
882 ms |
45420 KB |
Output is correct |
2 |
Correct |
998 ms |
45420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
768 ms |
45420 KB |
Output is correct |
2 |
Correct |
1435 ms |
50996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1368 ms |
56392 KB |
Output is correct |
2 |
Correct |
1170 ms |
56392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1626 ms |
62524 KB |
Output is correct |
2 |
Correct |
1566 ms |
64396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2147 ms |
73264 KB |
Output is correct |
2 |
Correct |
2078 ms |
73264 KB |
Output is correct |