lct90pts bao zha力
查看原帖
lct90pts bao zha力
251723
Schwarzkopf_Henkal楼主2021/1/7 14:59

具体来说,我到OIwiki上面贺了个板子过来,发现假掉了,改了一个奇怪的地方变成了91分,但是发现我普通平衡树也这么写,遂发现从splay到lct,我就没学过一个正确的板子。

WA on test9. Wrong Answer. wrong answer On line 50001 column 2, read 3, expected 0.

不懂出了什么问题,求教神仙

#include<bits/stdc++.h>
using namespace std;
struct lct{
    const static int N=100005;
    int ch[N][2],fa[N],val[N],sum[N],tag[N],siz[N];
    #define ls(o) ch[o][0]
    #define rs(o) ch[o][1]
    bool Get(int o){
        return ch[fa[o]][1]==o;
    }
    bool isRoot(int o){
        return ch[fa[o]][0]!=o&&ch[fa[o]][1]!=o;
    }
    void Up(int o){
        sum[o]=sum[ls(o)]^sum[rs(o)]^val[o];
        siz[o]=siz[ls(o)]+siz[rs(o)]+1;
    }
    void Down(int o){
        if(tag[o]){
            if(ls(o)){
                swap(ls(ls(o)),rs(ls(o)));
                tag[ls(o)]^=1;
            }
            if(rs(o)){
                swap(ls(rs(o)),rs(rs(o)));
                tag[rs(o)]^=1;
            }
            tag[o]=0;
        }
    }
    void update(int o){
        if(!isRoot(o))
            update(fa[o]);
        Down(o);
    }
    void rotate(int o){
        int u=fa[o],v=fa[fa[o]],w=Get(o);
        if(!isRoot(u))
            ch[v][rs(v)==u]=o;
        ch[u][w]=ch[o][!w];
        fa[ch[o][!w]]=u;
        ch[o][!w]=u;
        fa[u]=o;
        fa[o]=v;
        Up(u);
        Up(o);
    }
    void splay(int o){
        update(o);
        for(int f;f=fa[o],!isRoot(o);rotate(o))
            if(!isRoot(f))
                rotate(Get(f)==Get(o)?f:o);
        Up(o);
    }
    int access(int o){
        update(o);
        int u=0;
        while(o){
            splay(o);
            rs(o)=u;
            Up(o);
            u=o;
            o=fa[o];
        }
        return u;
    }
    void makeRoot(int o){
        access(o);
        splay(o);
        swap(ls(o),rs(o));
        tag[o]^=1;
    }
    int find(int u){
        access(u);
        splay(u);
        while(ls(u)){
            Down(u);
            u=ls(u);
        }
        splay(u);
        return u;
    }
    void link(int u,int v){
        makeRoot(u);
        if(find(v)!=u)
            fa[u]=v;
    }
    void split(int u,int v){
        makeRoot(u);
        access(v);
        splay(v);
    }//?
    void cut(int u,int v){
        makeRoot(u);
        access(v);
        splay(v);
        if(find(v)==u&&fa[v]==u&&ls(v)==0){
            ls(v)=fa[u]=0;
            Up(v);
        }
    }
}R;
int n,m,a[100005];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        R.val[i]=a[i];
        R.Up(i);
    }
    for(int i=1,typ,u,v;i<=m;i++){
        scanf("%d%d%d",&typ,&u,&v);
        if(typ==0){
            R.split(u,v);
            // cout<<R.ls(v)<<" "<<R.rs(v)<<" "<<R.fa[v]<<'\n';
            printf("%d\n",R.sum[v]);
        }
        if(typ==1){
            R.link(u,v);
        }
        if(typ==2){
            R.cut(u,v);
        }
        if(typ==3){
            R.splay(u);
            R.val[u]=v;
        }
    }
}/*

*/
2021/1/7 14:59
加载中...