其他分享
首页 > 其他分享> > 堆板子计划

堆板子计划

作者:互联网

LCT*1
struct LCT_Tree{
	#define lch V[p].son[0]
	#define rch V[p].son[1]
	#define Isroot(p) (V[V[p].fa].son[0]!=p && V[V[p].fa].son[1]!=p)
	#define Son(p) (V[V[p].fa].son[1]==p)
	struct Vertex{int son[2],siz,sum,t1,fa;}V[maxn];
	int tot;
	int New(int x,int fa){++tot;V[tot].sum=x;V[tot].siz=1;V[tot].fa=fa;return tot;}

	void Pushup(int p){V[p].siz=V[lch].siz+V[rch].siz+1;}
	void Upt1(int p){swap(lch,rch);V[p].t1^=1;}
	void Pusht1(int p){if(V[p].t1)Upt1(lch),Upt1(rch),V[p].t1=0;}
	void Pushdown(int p){Pusht1(p);}
	void Spread(int p){if(!Isroot(p))Spread(V[p].fa);Pushdown(p);}
	
	void Rotate(int p){
		int f=V[p].fa,lf=V[f].fa,s=Son(p),ls=Son(f);
		if(!Isroot(f))V[lf].son[ls]=p;
		V[f].son[s]=V[p].son[s^1],V[V[p].son[s^1]].fa=f;
		V[p].son[s^1]=f,V[f].fa=p;
		V[p].fa=lf;
		Pushup(f),Pushup(p);
	}
	void Splay(int p){
		Spread(p);
		for(int f=V[p].fa;!Isroot(f);f=V[p].fa){
			if(!Isroot(f))Rotate( Son(f) == Son(p) ? f : p );
		}
	}
	
	void Access(int x){int p;for(p=0;x;p=x,x=V[x].fa)Splay(x),V[x].son[1]=p,Pushup(x);}
	void Makeroot(int x){Access(x);Splay(x);Upt1(x);}
	int Findroot(int p){Access(p);Splay(p);Pushdown(p);while(V[p].son[0])p=lch,Pushdown(p);return p;}
	void Split(int x,int y){Makeroot(x),Access(y);Splay(y);}
	void Link(int x,int y){Makeroot(x);V[x].fa=y;}
	void Cut(int x,int y){Split(x,y);if(V[y].son[0]==x)V[y].son[0]=V[x].fa=0;Pushup(y);}

}L;

标签:int,void,tot,son,fa,计划,Pushup,板子
来源: https://www.cnblogs.com/Delov/p/16516132.html