Submission #259002

# Submission time Handle Problem Language Result Execution time Memory
259002 2020-08-07T01:36:59 Z thebes Sweeping (JOI20_sweeping) C++14
1 / 100
18000 ms 328380 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native")
#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 = 7500;
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{
    pii st[6*MM]; int n, k;
    void init(int N){
        n=N;
    }
    void clear(){
        memset(st,0,sizeof(st));
        k=0;
    }
    void upd(int i,int s,int e,int ss,int se,int val,int t){
        if(s>=ss&&e<=se) st[i]={val,t};
        else{
            if((s+e)/2<ss) upd(2*i+1,(s+e)/2+1,e,ss,se,val,t);
            else if((s+e)/2>=se) upd(2*i,s,(s+e)/2,ss,se,val,t);
            else upd(2*i,s,(s+e)/2,ss,se,val,t),upd(2*i+1,(s+e)/2+1,e,ss,se,val,t);
            st[i]=st[2*i].S>st[2*i+1].S?st[2*i]:st[2*i+1];
        }
    }
    inline void update(int l,int r,int val){
        if(l<=r) upd(1,1,n,l,r,val,++k);
    }
    pii qu(int i,int s,int e,int ind){
        if(s^e){
            pii cur;
            if((s+e)/2<ind) cur=qu(2*i+1,(s+e)/2+1,e,ind);
            else cur=qu(2*i,s,(s+e)/2,ind);
            return st[i].S>cur.S?st[i]:cur;
        }
        else return st[i];
    }
    inline int query(int ind){
        return qu(1,1,n,ind).F;
    }
}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){
                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){
                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++){
            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++){
            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;
    }
    return 0;
}

Compilation message

sweeping.cpp: In function 'int main()':
sweeping.cpp:57: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:59: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:64: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:66: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 84 ms 95352 KB Output is correct
2 Correct 91 ms 95088 KB Output is correct
3 Correct 69 ms 95352 KB Output is correct
4 Correct 92 ms 95352 KB Output is correct
5 Correct 116 ms 94840 KB Output is correct
6 Correct 83 ms 94584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 18104 ms 325332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 18036 ms 328380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 18036 ms 328380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 95352 KB Output is correct
2 Correct 91 ms 95088 KB Output is correct
3 Correct 69 ms 95352 KB Output is correct
4 Correct 92 ms 95352 KB Output is correct
5 Correct 116 ms 94840 KB Output is correct
6 Correct 83 ms 94584 KB Output is correct
7 Execution timed out 18104 ms 325332 KB Time limit exceeded
8 Halted 0 ms 0 KB -