split(u,v) 之后,可以直接断掉 splay 上的边并更新信息。这样写常数更小~
代码示例:
void merge(const int i, const int j) {
if(i == j) return;
if(check(i, j)) {
++tot;
queue<int> q;
q.push(i);
while(!q.empty()) {
const int u = q.front(); q.pop();
tr[u].f = tot;
pushdown(u);
if(tr[u].ch[0]) q.push(tr[u].ch[0]), tr[u].ch[0] = 0;
if(tr[u].ch[1]) q.push(tr[u].ch[1]), tr[u].ch[1] = 0;
pushup(u);
}
}
else tr[i].f = j;
}