QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#670875#5113. BridgeLYLAKIOIAKIOIRE 3ms29804kbC++144.7kb2024-10-24 07:46:462024-10-24 07:46:47

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 07:46:47]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:29804kb
  • [2024-10-24 07:46:46]
  • 提交

answer


#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define ll long long
using namespace std;
const int N=5e5+10;
struct FHQ{
    struct tree{
        int ls,rs,ky,sz,fa,rd,bl;
    }T[N];int tot=0;
    #define lc(x) T[x].ls
    #define rc(x) T[x].rs
    #define fa(x) T[x].fa
    inline void sp(int now,int ky,int &mn,int &mx){
        if(!now){
            mn=0;mx=0;return ;
        }if(T[now].ky<=ky){
            mn=now;
            sp(rc(now),ky,rc(now),mx);
            assert(now!=rc(now));
            if(rc(now)) fa(rc(now))=now;
        }else{
            mx=now;
            sp(lc(now),ky,mn,lc(now));
            assert(now!=lc(now));
            if(lc(now)) fa(lc(now))=now;
        }
    }inline int mg(int a,int b){
        if(!a||!b) return a^b;
        //return a;
        if(T[a].rd<=T[b].rd){
            rc(a)=mg(rc(a),b);
            //cout<<rc(a)<<' '<<a<<endl;
            assert(a!=rc(a));
            if(rc(a)) fa(rc(a))=a;
            return a;
        }else{
            lc(b)=mg(a,lc(b));
            //cout<<lc(b)<<' '<<b<<endl;
            assert(b!=lc(b));
            if(lc(b)) fa(lc(b))=b;
            return b;
        }
    }inline int add(int ky,int sz,int bl){
        tree x=(tree){0,0,ky,sz,0,rand(),bl};//x.ky=ky,x.rd=rand(),x.sz=sz,x.bl=bl;x.rs=0,x.ls=0;x.fa=0;
        T[++tot]=x;
        return tot;
    }int rt[N];
    inline void init(int sz,int len){
        for(int i=1;i<=sz;i++){
            rt[i]=add(1,len,i);
        }
    }inline int sp_nd(int id,int len){
        int olen=T[id].sz;
        T[id].sz=len;
        return add(T[id].ky+len,olen-len,T[id].bl);
    }inline int dfs(int now,int tim){
        //if(tim>1000) assert(0);
        //cout<<now<<' '<<rc(now)<<endl;
        if(!rc(now)||!now) return T[now].bl;return dfs(rc(now),tim+1);
    }inline int fd_r(int now,int tim){
        //if(tim>1000) assert(0);
        //if(now==fa(now)&&now!=0){
        //    cout<<now<<endl;exit(0);
        //}
        if(!fa(now)||!now) return now;//cout<<"JP8"<<tim<<endl;;
        return fd_r(fa(now),tim+1);
    }
}FHQ;
int n,m,q;
struct qu{
    int l,r,bl;
    bool operator<(const qu &b)const{
        if(l==b.l) return r<b.r;
        else return l<b.l;
    }bool operator>(const qu &b)const{
        if(l==b.l) return r>b.r;
        else return l>b.l;
    }
};
set<qu> bel[N];
inline int fd(int x,int y){
    /*for(auto it:bel[x]){
        cout<<it.l<<' '<<it.r<<' '<<it.bl<<endl;
    }*/
    auto ed=bel[x].upper_bound((qu){y,0x3f3f3f3f,0});
    //cout<<(*(--ed)).bl<<"---"<<endl;
    //if(ed!=bel[x].end()) cout<<(*ed).bl<<' ';
    //auto f=ed;f--;cout<<(*f).bl<<' '<<(*f).l<<' '<<(*f).r<<"---"<<endl;
    return (*(--ed)).bl;
}
int main(){
    //double c=clock();
    srand(time(0));
    ios::sync_with_stdio(0);
    cin>>n>>m>>q;
    FHQ.init(n,m+1);for(int i=1;i<=n;i++) bel[i].insert((qu){1,m+1,i});
    while(q--){
        int op;cin>>op;int a1,b1;
        if(op==1) cin>>a1>>b1;else cin>>a1;
        if(op==1){
            int x=fd(a1,b1+1),y=fd(a1+1,b1+1);
            //cout<<x<<' '<<y<<endl;
            int rx=FHQ.fd_r(x,0),ry=FHQ.fd_r(y,0);
            int pl=FHQ.T[x].ky-1,pr=FHQ.T[y].ky-1;
            int ql=FHQ.T[x].sz+pl,qr=FHQ.T[y].sz+pr;
            int a=0,b=0,c=0,d=0,e=0,f=0;
            FHQ.sp(rx,pl,a,b);FHQ.sp(ry,pr,d,e);
            FHQ.sp(b,ql,b,c);FHQ.sp(e,qr,e,f);
            bel[FHQ.T[b].bl].erase((qu){FHQ.T[b].ky,FHQ.T[b].ky+FHQ.T[b].sz-1,b});
            bel[FHQ.T[e].bl].erase((qu){FHQ.T[e].ky,FHQ.T[e].ky+FHQ.T[e].sz-1,e});
            //assert(b<=400000);
            int ga=FHQ.sp_nd(b,b1-FHQ.T[b].ky+1),gb=FHQ.sp_nd(e,b1-FHQ.T[e].ky+1);
            //cout<<a<<' '<<b<<' '<<c<<endl;
            //cout<<d<<' '<<e<<' '<<f<<endl;
            //cout<<ga<<' '<<gb<<endl;
            //cout<<FHQ.T[b].ky<<' '<<FHQ.T[e].ky<<endl;
            bel[FHQ.T[b].bl].insert((qu){FHQ.T[b].ky,FHQ.T[b].ky+FHQ.T[b].sz-1,b});
            bel[FHQ.T[e].bl].insert((qu){FHQ.T[e].ky,FHQ.T[e].ky+FHQ.T[e].sz-1,e});
            bel[FHQ.T[ga].bl].insert((qu){FHQ.T[ga].ky,FHQ.T[ga].ky+FHQ.T[ga].sz-1,ga});
            bel[FHQ.T[gb].bl].insert((qu){FHQ.T[gb].ky,FHQ.T[gb].ky+FHQ.T[gb].sz-1,gb});
            rx=FHQ.mg(FHQ.mg(a,b),FHQ.mg(gb,f));
            ry=FHQ.mg(FHQ.mg(d,e),FHQ.mg(ga,c));
        }else{
            int x=fd(a1,1);
            //cout<<x<<' ';
            int r=FHQ.fd_r(x,0);
            //cout<<r<<" fd"<<endl;
            //cout<<r<<endl;
            cout<<FHQ.dfs(r,0)<<endl;
        }
        //if((((clock()-c)/CLOCKS_PER_SEC)>1.0)) exit(0);
    }cout.flush();//cerr<<(clock()-c)/CLOCKS_PER_SEC;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 29804kb

input:

3 4 13
2 2
1 1 3
2 1
2 2
2 3
1 2 4
2 1
2 2
2 3
1 2 1
2 1
2 2
2 3

output:

2
2
1
3
3
1
2
3
2
1

result:

ok 10 numbers

Test #2:

score: -100
Runtime Error

input:

3 100000 99997
2 2
2 2
2 3
2 3
2 3
2 3
2 3
1 2 11047
1 1 98732
1 2 90045
1 1 43556
2 1
2 3
1 2 17242
1 1 17027
2 1
1 1 94195
2 1
2 2
2 1
2 3
1 1 34124
1 2 14354
1 2 673
1 2 39812
1 2 35520
1 2 16046
2 3
2 2
1 1 25410
2 3
2 1
2 3
2 2
1 2 55684
2 1
1 2 24811
1 2 92268
1 2 60268
2 2
1 1 89272
1 2 19232...

output:

2
2
3
3
3
3
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result: