可以不使用 DFS 建方点
查看原帖
可以不使用 DFS 建方点
1402161
XuHenry楼主2025/7/3 22:37

split(u,v)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;
}
2025/7/3 22:37
加载中...