TAT,我的LCT转双旋了

这里是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

 

posted @ 2015-06-06 11:11  wzj_is_a_juruo  阅读(362)  评论(2编辑  收藏  举报