splay

xiaoxiao2021-02-27  523

写一个极短的splay函数:

int ch[N][2], v[N], fa[N], Index, m; void rotate(int x){ int y = fa[x], f = fa[y], t = ch[y][1] == x; fa[ch[y][t] = ch[x][t^1]] = y, fa[ch[x][t^1] = y] = x; if (fa[x] = f) ch[f][ch[f][1]==y] = x; } void splay(int x){ for(int y;y=fa[x];rotate(x)) if(fa[y]) rotate(((lc(y)==x)^(lc(fa[y])==y))?x:y); }
转载请注明原文地址: https://www.6miu.com/read-3810.html

最新回复(0)