zoukankan      html  css  js  c++  java
  • 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);
    }
    
  • 相关阅读:
    测试用例的设计
    测试经理的职责
    如果开发认为这不是bug,对QA来说应该怎么处理?
    我选择测试的过程
    API的知识点
    测试人员需要的技能
    时区转换的计算方式
    学习能力的必需
    制图工具
    JSON序列和反序列1
  • 原文地址:https://www.cnblogs.com/clover4/p/13139531.html
Copyright © 2011-2022 走看看