好的LCT板子和一句话


typedef long long ll;

const int maxn = 400050;

struct lct {
    int ch[maxn][2], fa[maxn], w[maxn];
    bool col[maxn], rev[maxn];
    ll lans[maxn], rans[maxn], ans[maxn], tt[maxn], tt2[maxn], w2[maxn];
    inline void Rev(const int& x) {
        if(x) {
            rev[x] ^= 1;
            swap(ch[x][0], ch[x][1]);
            swap(lans[x], rans[x]);
        }
    }
    inline bool isroot(int x) {
        return ch[fa[x]][0] != x && ch[fa[x]][1] != x;
    }
    inline void pushdown(const int& x) {
        if(!x) return;
        if(!isroot(x)) pushdown(fa[x]);
        if(rev[x]) {
            Rev(ch[x][0]); Rev(ch[x][1]);
            rev[x] = 0;
        }
    }
    inline void maintain(const int& x) {
        if(!x) return;
        w2[x] = w2[ch[x][0]] + w2[ch[x][1]] + w[x];
        tt[x] = ;
        lans[x] = ;
        rans[x] = ;
    }
    inline void rotate(int x) {
        int f = fa[x], ff = fa[f], d = x == ch[f][1];
        if(!isroot(f)) ch[ff][f==ch[ff][1]] = x;
        fa[x] = ff;
        ch[f][d] = ch[x][d^1];
        if(ch[x][d^1]) fa[ch[x][d^1]] = ch[f][d];
        ch[x][d] = f; fa[f] = x;
        maintain(f);
    }
    inline void splay(int x) {
        pushdown(x);
        for(int f = fa[x], ff = fa[f]; !isroot(x); rotate(x), f = fa[x], ff = fa[f])
            if(!isroot(y)) rotate((x==ch[f][1])==(f==ch[ff][1])?f:x);
        maintain(x);
    }
    inline void access(int x) {
        int son = 0;
        while(x) {
            splay(x);
            ch[x][1] = son;
            maintain(x);
            son = x; x = fa[x];
        }
    }
    inline void mroot(int x) {
        access(x); splay(x);
        Rev(x);
    }
    inline void linkto(int u, int v) {
        mroot(x); mroot(v);
        fa[u] = v;
        maintain(v);
    }
    inline void cutfrom(int u, int v) {
        mroot(v); access(u); splay(u);
        int root = ch[v][0];
        ch[root][0] = fa[root] = ch[v][0] = fa[root] = 0;
        maintain(v);
    }
    
    

“自信可改变未来。”
是谁在夏令营说的说的来着?

进队=做大家都会的题+暴力全部打满
boj kt 基本没有这样的情况:因为时间不够没有想出做法。

猜你喜欢

转载自www.cnblogs.com/utopia999/p/10486878.html