众所周知Splay中的insert非递归写法如下
void ins(int x){
if(!rt){
val[++tot]=x;
rt=tot;
cnt[tot]++;
update(rt);
return;
}
int cnr=rt,f=0;
while(1){
if(x==val[cnr]){
cnt[cnr]++;
update(cnr);
update(f);
splay(cnr);
return;
}
f=cnr;
cnr=ch[cnr][val[cnr]<x];
if(!cnr){
val[++tot]=x;
cnt[tot]++;
fa[tot]=f;
ch[f][val[f]<x]=tot;
update(tot);
update(f);
splay(tot);
}
}
}
其中
if(x==val[cnr]){
cnt[cnr]++;
update(cnr);
update(f);
splay(cnr);
return;
}
更新了他自己和父亲那么父亲上面怎么办a