• LCT板子


    #define ls(x) ch[x][0]
    #define rs(x) ch[x][1]
    int fa[N], ch[N][2], sum[N], val[N], rev[N];
    inline void update(int x) { sum[x] = sum[ls(x)] ^ sum[rs(x)] ^ val[x]; }
    inline int nroot(int x) { return ls(fa[x]) == x || rs(fa[x]) == x; }
    inline int get(int x) { return rs(fa[x]) == x; }
    inline void rotate(int x) {
    	int y = fa[x], z = fa[y], k = get(x), w = ch[x][!k];
    	if(nroot(y)) ch[z][get(y)] = x; ch[x][!k] = y; ch[y][k] = w;
    	if(w) fa[w] = y; fa[y] = x; fa[x] = z; update(y);
    }
    inline void pushdown(int x) {
    	if(rev[x]) {swap(ls(x), rs(x));
    		if(ls(x)) rev[ls(x)] ^= 1; if(rs(x)) rev[rs(x)] ^= 1;
    		 rev[x] = 0;
    	}
    }
    inline void pushall(int x) { if(nroot(x)) pushall(fa[x]); pushdown(x); }
    inline void splay(int x) {
    	pushall(x);
    	while(nroot(x)) {
    		if(nroot(fa[x])) rotate(get(x) ^ get(fa[x]) ? x : fa[x]);
    		rotate(x);
    	} update(x);
    }
    inline void access(int x) {
    	for(R int y = 0; x; x = fa[y = x]) splay(x), rs(x) = y, update(x);
    }
    inline void makeroot(int x) { access(x); splay(x); rev[x] ^= 1; }
    inline void split(int x, int y) { makeroot(x); access(y); splay(y); }
    inline int findroot(int x) {
    	access(x); splay(x); while(ls(x)) pushdown(x), x = ls(x); splay(x); return x;
    }
    inline void link(int x, int y) {
    	makeroot(x);  if(findroot(y) != x) fa[x] = y, update(y);
    }
    inline void cut(int x, int y) {
    	makeroot(x);
    	if(findroot(y) == x && fa[y] == x && ls(y) == 0) ch[x][1] = fa[y] = 0, update(x);
    }
    
  • 相关阅读:
    关于android 中WebView使用Css
    android下面res目录
    Android View如何获取焦点
    用javascript修改html元素的class
    设计模式-观察者模式(List列表维护观察者)
    闭包->类的实例数组排序
    Javascript setTimeout 带参数延迟执行 闭包实现
    最简单的闭包 掰开揉碎
    原创最简单的ORM例子
    List<T> 转换 DataTable
  • 原文地址:https://www.cnblogs.com/clover4/p/13139531.html
Copyright © 2020-2023  润新知