跳到正文

剪贴板

剪贴板 7dkooj1i

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include <bits/stdc++.h>

using namespace std;

const int maxn=1.5e6;

struct oper {
    int o,l,r,x,id;
    oper() { o=l=r=x=id=0; }
    oper(int a,int b,int c,int d,int e) {
        o=a,l=b,r=c,x=d,id=e;
    }
} O[maxn+5],tmp[maxn+5];
pair<int,int> trans[maxn+5];
int n,m,q;
int sta1[maxn+5],top1,sta2[maxn+5],top2;
int nwl[maxn+5],nwr[maxn+5],vis[maxn+5];
pair<int,int> ans[maxn+5];
struct DSU {
    int fa[maxn+5],siz[maxn+5];
    int head[maxn+5],tail[maxn+5],nxt[maxn+5];
    int find(int x) {
        while (fa[x]!=x) x=fa[x];
        return x;
    }
    int merge(int x,int y) {
        int fx=find(x),fy=find(y);
        if (fx==fy) return fx;
        if (siz[fx]<siz[fy]) swap(fx,fy);
        fa[fy]=fx; siz[fx]+=siz[fy];
        nxt[tail[fx]]=head[fy];
        tail[fx]=tail[fy];
        return fx;
    }
} Ldsu,Rdsu;

struct cmp1 {
    bool operator() (const oper &x,const oper &y) {
        return x.l>y.l;
    }
} ;
struct cmp2 {
    bool operator() (const oper &x,const oper &y) {
        return x.r<y.r;
    }
} ;

void solve(int L,int R,int ln,int rn) {
    if (ln>rn) return ;
    if (L==R) {
        for (int j=ln;j<=rn;j++) {
            if (O[j].o==1) {
                ans[O[j].id]={L,L};
            }
        }
        return ;
    }
    int lpos=ln,rpos=rn;
    int mid=(L+R)>>1;
    {
    priority_queue<oper,vector<oper>,cmp1> Ql;
    priority_queue<oper,vector<oper>,cmp2> Qr;
    for (int i=ln;i<=rn;i++) {
        auto [o,l,r,x,id]=O[i];
        if (o==1) {
            if (vis[x]==1) {
                tmp[lpos++]=oper(o,l,r,x,id);
            } else if (vis[x]==2) {
                tmp[rpos--]=oper(o,l,r,x,id);
            } else {
                ans[id]={nwl[Ldsu.find(x)],nwr[Rdsu.find(x)]};
            }
        } else if (o==4) {
            if (r<=mid) {
                tmp[lpos++]=oper(o,l,r,x,id);
                vis[id]=1;
                continue ;
            }
            if (mid<l) {
                tmp[rpos--]=oper(o,l,r,x,id);
                vis[id]=2;
                continue ;
            }
            nwl[id]=l;
            nwr[id]=r;
            Ldsu.fa[id]=id;
            Ldsu.siz[id]=1;
            Ldsu.head[id]=Ldsu.tail[id]=id;
            Ldsu.nxt[id]=0;
            Rdsu.fa[id]=id;
            Rdsu.siz[id]=1;
            Rdsu.head[id]=Rdsu.tail[id]=id;
            Rdsu.nxt[id]=0;
            vis[id]=0;
            Ql.emplace(4,l,r,0,id);
            Qr.emplace(4,l,r,0,id);
        } else if (x<=mid) {
            tmp[lpos++]=oper(o,l,r,x,id);
            if (o==2) {
                if (!Ql.size()) continue ;
                int lstid=0;
                while (!Ql.empty()) {
                    oper nw=Ql.top();
                    if (nw.l>=x) break ;
                    Ql.pop();
                    if (!lstid) {
                        lstid=nw.id;
                    } else {
                        lstid=Ldsu.merge(nw.id,lstid);
                    }
                }
                if (lstid) {
                    Ql.emplace(0,x,0,0,lstid);
                    nwl[lstid]=x;
                }
            } else {
                while (!Ql.empty()) {
                    oper nw=Ql.top();
                    if (nw.l>x) break ;
                    Ql.pop();
                    int lp=nw.l;
                    int u=nw.id;
                    while(u) {
                        if (vis[u]==0) {
                            vis[u]=1;
                            tmp[lpos++]=oper(4,lp,x,0,u);
                        }
                        u=Ldsu.nxt[u];
                    }
                }
            }
        } else {
            tmp[rpos--]=oper(o,l,r,x,id);
            if (o==3) {
                if (!Qr.size()) continue ;
                int lstid=0;
                while (!Qr.empty()) {
                    oper nw=Qr.top();
                    if (nw.r<=x) break ;
                    Qr.pop();
                    if (!lstid) {
                        lstid=nw.id;
                    } else {
                        lstid=Rdsu.merge(lstid,nw.id);
                    }
                }
                if (lstid) {
                    Qr.emplace(4,0,x,0,lstid);
                    nwr[lstid]=x;
                }
            } else {
                while (!Qr.empty()) {
                    oper nw=Qr.top();
                    if (nw.r<x) break ;
                    Qr.pop();
                    int rp=nw.r;
                    int u=nw.id;
                    while(u) {
                        if (vis[u]==0) {
                            vis[u]=2;
                            tmp[rpos--]=oper(4,x,rp,0,u);
                        }
                        u=Rdsu.nxt[u];
                    } ;
                }
            }
        }
    }
    }
    for (int i=ln;i<=rn;i++) O[i]=tmp[i];
    reverse(O+rpos+1,O+rn+1);
    solve(L,mid,ln,lpos-1);
    solve(mid+1,R,rpos+1,rn);

}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m>>q;
    int mcnt=m;
    int cnt=0;
    for (int i=1;i<=m;i++) {
        int x,y;
        cin>>x>>y;
        y=n-y;
        O[++cnt]=oper(4,x,y,0,i);
    }
    int qcnt=0;
    for (int i=1;i<=q;i++) {
        int o;
        cin>>o;
        if (o==1) {
            int x;
            cin>>x;
            O[++cnt]=oper(o,0,0,x,++qcnt);
        } else if (o==2) {
            int x;
            cin>>x;
            O[++cnt]=oper(o,0,0,n-x,0);
        } else if (o==3) {
            int x;
            cin>>x;
            O[++cnt]=oper(o,0,0,x,0);
        } else {
            int x,y;
            cin>>x>>y;
            y=n-y;
            O[++cnt]=oper(o,x,y,0,++mcnt);
        }
    }
    solve(0,1e9,1,cnt);
    for (int i=1;i<=qcnt;i++) cout<<ans[i].first<<' '<<n-ans[i].second<<'\n';
    return 0;
}