您的位置:首页 > 其它

TAT,我的LCT转双旋了

2015-06-06 11:11 302 查看
这里是rotate和splay函数

void rotate(int x)
{
int y=pre[x],z=pre[y],d=ch[y][0]==x;
ch[y][d^1]=ch[x][d];pre[ch[x][d]]=y;
ch[z][ch[z][1]==y]=x;pre[x]=z;
ch[x][d]=y;pre[y]=x;maintain(y);
}
int q[maxn],top;
void splay(int x)
{
for(int i=x;i;i=pre[i]) q[++top]=i;
if(q[top]!=x) fa[x]=fa[q[top]],fa[q[top]]=0;
while(top) pushdown(q[top--]);
while(pre[x])
{
int y=pre[x],z=pre[y];
if(pre[y]) if(ch[y][0]==x^ch[z][0]==y) rotate(x);else rotate(y);
rotate(x);
}
maintain(x);
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: