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