# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
258998 |
2020-08-07T01:11:54 Z |
thebes |
Sweeping (JOI20_sweeping) |
C++14 |
|
18000 ms |
300516 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define F first
#define S second
const int MN = 5e5+5, MM = 1e6+6, MB = 5000;
int N, M, Q, i, j, k, t, x, y, nxt, ac[MB+100], id[6*MM], on[6*MM], ox[6*MM], oy[6*MM], ot[MB], rx[6*MM], ry[6*MM], ax[6*MM], ay[6*MM];
tuple<int,int,int> arr[MM];
pii pos[2*MM], op[MB+100], rr[MB+100];
map<int,int> mpx, mpy;
unordered_map<int,int> mx, my;
struct idk{int x, l, r;};
vi vec, pnt;
struct segtree{
int st[6*MM], lz[6*MM], n;
void init(int N){
n=N;
memset(lz,-1,sizeof(lz));
}
void clear(){
lz[1]=0;
}
inline void upd_lz(int i,int s,int e){
if(lz[i]!=-1){
st[i]=lz[i];
if(s!=e) lz[2*i]=lz[2*i+1]=lz[i];
lz[i]=-1;
}
}
void upd(int i,int s,int e,int ss,int se,int val){
upd_lz(i,s,e);
if(s>=ss&&e<=se) lz[i]=val, upd_lz(i,s,e);
else{
if((s+e)/2<ss) upd(2*i+1,(s+e)/2+1,e,ss,se,val), upd_lz(2*i,s,(s+e)/2);
else if((s+e)/2>=se) upd(2*i,s,(s+e)/2,ss,se,val), upd_lz(2*i+1,(s+e)/2+1,e);
else upd(2*i,s,(s+e)/2,ss,se,val), upd(2*i+1,(s+e)/2+1,e,ss,se,val);
}
}
inline void update(int l,int r,int val){
if(l<=r) upd(1,1,n,l,r,val);
}
int qu(int i,int s,int e,int ind){
upd_lz(i,s,e);
if(s^e){
if((s+e)/2<ind) return qu(2*i+1,(s+e)/2+1,e,ind);
else return qu(2*i,s,(s+e)/2,ind);
}
else return st[i];
}
inline int query(int ind){
return qu(1,1,n,ind);
}
}stx,sty;
int main(){
scanf("%d%d%d",&N,&M,&Q);
for(i=1;i<=M;i++){
scanf("%d%d",&x,&y);
pos[++nxt]={x,y};
mpx[x]=mpy[y]=0;
}
for(i=1;i<=Q;i++){
scanf("%d%d",&t,&x);
if(t==4){
scanf("%d",&y);
arr[i]=make_tuple(t,x,y);
mpx[x]=mpy[y]=0;
}
else{
arr[i]=make_tuple(t,x,0);
if(t==2) mpy[x]=mpx[N-x]=0;
else if(t==3) mpx[x]=mpy[N-x]=0;
}
}
i=0;
for(auto it=mpx.begin();it!=mpx.end();it++){
it->second = ++i, rx[i] = it->first;
mx[it->first]=it->second;
}
stx.init(mpx.size());
i=0;
for(auto it=mpy.begin();it!=mpy.end();it++){
it->second = ++i, ry[i] = it->first;
my[it->first]=it->second;
}
sty.init(mpy.size());
for(i=1;i<=M;i++){
pos[i].F=mpx[pos[i].F];
pos[i].S=mpy[pos[i].S];
}
for(i=1;i<=Q;i++){
if(get<0>(arr[i])==2) arr[i]=make_tuple(2,mpy[get<1>(arr[i])],0);
else if(get<0>(arr[i])==3) arr[i]=make_tuple(3,mpx[get<1>(arr[i])],0);
else if(get<0>(arr[i])==4) arr[i]=make_tuple(4,mpx[get<1>(arr[i])],mpy[get<2>(arr[i])]);
}
for(i=1;i<=Q;i+=MB){
int ed = min(Q, i+MB-1);
int pcnt = 0, ecnt = 0;
for(j=i;j<=ed;j++){
if(get<0>(arr[j])==1){
if(!on[get<1>(arr[j])]){
ac[++pcnt]=get<1>(arr[j]);
on[get<1>(arr[j])]=1;
id[j]=pcnt;
}
}
else if(get<0>(arr[j])==2){
if(!oy[get<1>(arr[j])]){
op[++ecnt]=make_pair(0,get<1>(arr[j]));
oy[get<1>(arr[j])]=1;
ot[ecnt]=mx[N-ry[get<1>(arr[j])]];
id[j]=ecnt;
}
}
else if(get<0>(arr[j])==3){
if(!ox[get<1>(arr[j])]){
op[++ecnt]=make_pair(1,get<1>(arr[j]));
ox[get<1>(arr[j])]=1;
ot[ecnt]=my[N-rx[get<1>(arr[j])]];
id[j]=ecnt;
}
}
}
for(j=i;j<=ed;j++){
if(get<0>(arr[j])==1){
int id=get<1>(arr[j]);
x = pos[id].F, y = pos[id].S;
printf("%d %d\n",rx[x],ry[y]);
}
else if(get<0>(arr[j])==2){
for(k=1;k<=pcnt;k++){
if(pos[ac[k]].S<=get<1>(arr[j]))
pos[ac[k]].F=max(pos[ac[k]].F,ot[id[j]]);
}
}
else if(get<0>(arr[j])==3){
for(k=1;k<=pcnt;k++){
if(pos[ac[k]].F<=get<1>(arr[j]))
pos[ac[k]].S=max(pos[ac[k]].S,ot[id[j]]);
}
}
else{
pos[++nxt]=make_pair(get<1>(arr[j]),get<2>(arr[j]));
ac[++pcnt]=nxt; on[nxt]=1;
id[j]=pcnt;
}
}
for(j=i;j<=ed;j++){
int pre = 0;
if(get<0>(arr[j])==2){
for(k=i;k<=j;k++){
if(get<0>(arr[k])==3){
if(rr[id[k]].F<=get<1>(arr[j])&&get<1>(arr[j])<rr[id[k]].S)
pre=max(pre,get<1>(arr[k]));
}
}
rr[id[j]]=make_pair(pre+1,ot[id[j]]);
}
else if(get<0>(arr[j])==3){
for(k=i;k<=j;k++){
if(get<0>(arr[k])==2){
if(rr[id[k]].F<=get<1>(arr[j])&&get<1>(arr[j])<rr[id[k]].S)
pre=max(pre,get<1>(arr[k]));
}
}
rr[id[j]]=make_pair(pre+1,ot[id[j]]);
}
}
vec.clear();
pnt.clear();
for(j=1;j<=ecnt;j++){
if(op[j].F==1) vec.push_back(j);
}
for(j=1;j<=nxt;j++){
ax[j]=ay[j]=0;
pnt.push_back(j);
}
sort(vec.begin(),vec.end(),[](int i,int j){return op[i].S>op[j].S;});
sort(pnt.begin(),pnt.end(),[](int i,int j){return pos[i].F>pos[j].F;});
stx.clear();
for(j=k=0;j<(int)pnt.size();j++){
//printf("%d %d\n",k==vec.size()?-1:vec[k],pnt[j]);
while(k<(int)vec.size()&&op[vec[k]].S>=pos[pnt[j]].F){
stx.update(rr[vec[k]].F,rr[vec[k]].S,rr[vec[k]].S);
k++;
}
ay[pnt[j]]=stx.query(pos[pnt[j]].S);
}
vec.clear();
for(j=1;j<=ecnt;j++){
if(op[j].F==0) vec.push_back(j);
}
sort(vec.begin(),vec.end(),[](int i,int j){return op[i].S>op[j].S;});
sort(pnt.begin(),pnt.end(),[](int i,int j){return pos[i].S>pos[j].S;});
sty.clear();
for(j=k=0;j<(int)pnt.size();j++){
//printf("%d %d\n",k==vec.size()?-1:vec[k],pnt[j]);
while(k<(int)vec.size()&&op[vec[k]].S>=pos[pnt[j]].S){
sty.update(rr[vec[k]].F,rr[vec[k]].S,rr[vec[k]].S);
k++;
}
ax[pnt[j]]=sty.query(pos[pnt[j]].F);
}
for(j=1;j<=nxt;j++){
if(!on[j]){
if(ax[j]) pos[j].F=ax[j];
if(ay[j]) pos[j].S=ay[j];
}
}
for(j=1;j<=pcnt;j++) on[ac[j]]=0;
for(j=1;j<=ecnt;j++){
if(op[j].F==0) oy[op[j].S]=0;
else ox[op[j].S]=0;
}
}
return 0;
}
Compilation message
sweeping.cpp: In function 'int main()':
sweeping.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&N,&M,&Q);
~~~~~^~~~~~~~~~~~~~~~~~~
sweeping.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&x,&y);
~~~~~^~~~~~~~~~~~~~
sweeping.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&t,&x);
~~~~~^~~~~~~~~~~~~~
sweeping.cpp:69:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&y);
~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
48504 KB |
Output is correct |
2 |
Correct |
57 ms |
48156 KB |
Output is correct |
3 |
Correct |
37 ms |
48380 KB |
Output is correct |
4 |
Correct |
54 ms |
48504 KB |
Output is correct |
5 |
Incorrect |
74 ms |
47864 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
18036 ms |
292096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
18076 ms |
300516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
18076 ms |
300516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
48504 KB |
Output is correct |
2 |
Correct |
57 ms |
48156 KB |
Output is correct |
3 |
Correct |
37 ms |
48380 KB |
Output is correct |
4 |
Correct |
54 ms |
48504 KB |
Output is correct |
5 |
Incorrect |
74 ms |
47864 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |