求助,全WA本地测却没问题,悬关(含测试数据)

P3391 【模板】文艺平衡树

就首先 你输出了两个序列啊喂!!! (是不是调试完忘打注释了... 然后然后 swap 未定义 头文件可以直接用 bits 就过了。。。 所以所以 ```cpp #include<cstdio> #include<cstring> #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, m, a[N]; int root, num, fa[N], cnt[N], val[N], tag[N], sz[N], son[N][2]; void update(int x){ sz[x] = cnt[x] + sz[son[x][0]] + sz[son[x][1]]; } void push(int x){ if(tag[x] == 0) return; tag[son[x][0]] ^= 1; tag[son[x][1]] ^= 1; swap(son[x][0], son[x][1]); tag[x] = 0; } int build(int l, int r, int fat){ if(l > r) return 0; int mid = (l + r) / 2; int temp = ++num; fa[temp] = fat; cnt[temp] = 1; val[temp] = a[mid]; son[temp][0] = build(l, mid - 1, temp); son[temp][1] = build(mid + 1, r, temp); update(temp); return temp; } bool which(int x){ return x == son[fa[x]][1]; } void zz(int x){ int f = fa[x], ff = fa[f]; push(x); push(f); int zy = which(x); son[f][zy] = son[x][zy ^ 1]; fa[son[f][zy]] = f; fa[f] = x; fa[x] = ff; son[x][zy ^ 1] = f; if(ff != x) son[ff][son[ff][1] == f] = x; update(f); } void splay(int x, int y){ for(int ff; (ff = fa[x]) != y; zz(x)) if(fa[ff] != y){ if(which(x) == which(ff)) zz(ff); else zz(x); } if(y == 0) root = x; } int getvbr(int rk){ int x = root; while(1){ push(x); if(rk <= sz[son[x][0]]) x = son[x][0]; else{ rk -= sz[son[x][0]] + cnt[x]; if(rk <= 0) return x; x = son[x][1]; } } } void rev(int x, int y){ int l = getvbr(x - 1), r = getvbr(y + 1); splay(l, 0); splay(r, l); tag[son[son[root][1]][0]] ^= 1; } void print(int x){ push(x); if(son[x][0]) print(son[x][0]); if(val[x] != -1e9 && val[x] != 1e9) printf("%d ", val[x]); if(son[x][1]) print(son[x][1]); } int main(){ scanf("%d%d", &n, &m); for(int i = 1; i <= n + 2; i++){ if(i == 1) a[i] = -1e9; else if(i == n + 2) a[i] = 1e9; else a[i] = i - 1; } root = build(1, n + 2, 0); // print(root); // puts(""); while(m--){ int x, y; scanf("%d%d", &x, &y); rev(x + 1, y + 1); } print(root); puts(""); return 0; } ```
by 柠檬熟了 @ 2023-09-04 18:45:31


@[little_magicstar](/user/325086)
by 柠檬熟了 @ 2023-09-04 18:46:25


@[柠檬熟了](/user/386597) 已关注,谢谢大佬
by little_magicstar @ 2023-09-09 19:26:56


|