萌新刚学OI,非常垃圾,啥也不会,求助一个弱弱的 Splay 旋转
  • 板块学术版
  • 楼主SIXIANG32
  • 当前回复4
  • 已保存回复4
  • 发布时间2020/10/25 14:24
  • 上次更新2023/11/5 09:55:19
查看原帖
萌新刚学OI,非常垃圾,啥也不会,求助一个弱弱的 Splay 旋转
298549
SIXIANG32楼主2020/10/25 14:24
bool LorR(int x){return tr[tr[x].fa].son[0]==x?0:1;}
	void updata(int x){tr[x].size=tr[tr[x].son[0]].size+tr[tr[x].son[1]].size+tr[x].cnt;}
	void link(int x,int fa,int son)
	{
		tr[x].fa=fa;
		tr[fa].son[son]=x;
	}
	void rotate(int x)
	{
		int fa=tr[x].fa;
		int fat=tr[fa].fa;
		int xs=LorR(x),fs=LorR(fa);
		int stre=tr[x].son[xs^1];
		link(stre,fa,xs),link(fa,x,(xs^1)),link(x,fat,fs);
		updata(fa),updata(x);
	}
	void splay(int x,int to)
	{
		to=tr[to].fa;
		while(tr[x].fa!=to)
		{
			int fat=tr[x].fa;
			if(tr[fat].fa==to)rotate(x);
			else if(LorR(x)==LorR(fat))rotate(fat),rotate(x);
			else rotate(x),rotate(x); 
		}
	}

求助 awa,调试调到头秃/kk/kk/kk

2020/10/25 14:24
加载中...