救救孩子吧!!!!50行代码调不出来!
查看原帖
救救孩子吧!!!!50行代码调不出来!
173660
zhoukangyang楼主2020/8/11 11:59

RT 49 行的LCT调不出来, 大佬们帮帮忙吧/kel

#include<bits/stdc++.h>
#define N 1500010
using namespace std;
int n, m, ans[2][N], ch[N][2], srf[N], fa[N], flag[N], lazy[N], v[N], sum[N];
int son[N][3];
bool get(int x) { return ch[fa[x]][0] == x || ch[fa[x]][1] == x;}
void xg(int x, int lz) {sum[x] += lz, lazy[x] += lz, swap(ans[0][x], ans[1][x]), v[x] = (sum[x] > 1);}
void pushdown(int x) {if(lazy[x]) xg(ch[x][0], lazy[x]), xg(ch[x][1], lazy[x]), lazy[x] = 0;}
void upd(int x) {
    ans[0][x] = ans[0][ch[x][0]] ? ans[0][ch[x][0]] : sum[x] - 1 ? x : ans[0][ch[x][1]];
    ans[1][x] = ans[1][ch[x][0]] ? ans[1][ch[x][0]] : sum[x] - 2 ? x : ans[1][ch[x][1]];
}
void rotate(int x) {
    int y = fa[x], z = fa[y], fson = (ch[y][1] == x), ano = ch[x][1 ^ fson];
    if(get(y)) ch[z][ch[z][1] == y] = x;
    if(ano) fa[ano] = y;
    fa[x] = z, fa[y] = x, ch[x][1 ^ fson] = y, ch[y][fson] = ano;
    upd(y), upd(x);
}
int f[N], fx, tot;
void Splay(int x) {
    tot = 1, fx = f[tot] = x;
    while(get(fx)) ++tot, f[tot] = fx = fa[fx];
    while(tot) pushdown(f[tot]), --tot;
    while(get(x)) {
        int y = fa[x], z = fa[y];
        if(get(y)) rotate((ch[y][1] == x) ^ (ch[z][1] == y) ? x : y);
        rotate(x);
    }
    upd(x);
}
void access(int x) { for(int y = 0; x; x = fa[y = x]) Splay(x), ch[x][1] = y, upd(x);}
void dfs(int x) {if(x <= n) dfs(son[x][0]), dfs(son[x][1]), dfs(son[x][2]), sum[x] = v[son[x][0]] + v[son[x][1]] + v[son[x][2]], v[x] = (sum[x] > 1);}
int x, gx, Ans;
int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) for(int t = 0; t < 3; t++) scanf("%d", &son[i][t]), fa[son[i][t]] = i;
    for(int i = n + 1; i <= 3 * n + 1; i++) scanf("%d", &v[i]);
    dfs(1), n = n * 3 + 1, Ans = v[1];
    scanf("%d", &m);
    while(m--) {
        scanf("%d", &x), gx = fa[x], access(gx), Splay(gx), upd(gx), v[x] ^= 1;
        int ad = (v[x] == 1 ? 1 : -1), w = ans[1 ^ v[x]][gx];
        if(w) Splay(w), xg(ch[w][1], ad), sum[w] += ad, upd(ch[w][1]), upd(w);
        else Ans ^= 1, xg(gx, ad), upd(gx);
        printf("%d\n", Ans);
    }
    return 0;
}
2020/8/11 11:59
加载中...