有关Splay的小问题,学过Splay的点进来点进来点进来
  • 板块学术版
  • 楼主peterwuyihong
  • 当前回复10
  • 已保存回复10
  • 发布时间2020/8/7 09:28
  • 上次更新2023/11/6 21:04:04
查看原帖
有关Splay的小问题,学过Splay的点进来点进来点进来
100325
peterwuyihong楼主2020/8/7 09:28

众所周知SplaySplay中的insertinsert非递归写法如下

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

2020/8/7 09:28
加载中...