// Jamhus Tao / GreatLiangpi // Start at 2022/10/6 // Please using int32_t and int64_t to replace the int and long long. #include<bits/stdc++.h> #define int int64_t #define endl '\n' #pragma GCC optimize(3, "Ofast", "inline") usingnamespace std;
// Splay constint MAX = 100005; constint INF = 0x3f3f3f3f3f3f3f3fll;
// 代码实现约定: // tr[0].sum 始终为 0, 其余随意; tr[root].father 始终为 0; root == 0 表示空树, next == 0 表示无儿子 structSplay { int key; // 键 int cnt; // 计数 int father; // 父节点 int next[2]; // 左右子节点 int sum; // 子树求和 } tr[MAX]; // 1-index int root = 0; int cnt_tr = 1;
// Jamhus Tao / GreatLiangpi // Start at 2022/10/6 // Please using int32_t and int64_t to replace the int and long long. #include<bits/stdc++.h> #define int int64_t #define endl '\n' #pragma GCC optimize(3, "Ofast", "inline") usingnamespace std;
// Splay 平衡树 structSplay { int father; int next[2]; int sum; bool lazy; } tr[MAX]; // 1-index int root = 0; int cnt_tr = 1;
// 维护 lazy 标记 inlinevoiddone(int x){ if (tr[x].lazy) { int &li = tr[x].next[0]; int &ri = tr[x].next[1]; tr[li].lazy ^= true; tr[ri].lazy ^= true; swap(li, ri); tr[x].lazy = false; } }
// 为父的右儿子 inlineboolwho(int x){ return x == tr[tr[x].father].next[1]; }
// 旋转使 x 上升 inlinevoidrotate(int x){ bool w = who(x); int f = tr[x].father, ff = tr[f].father, s = tr[x].next[not w]; tr[ff].next[who(f)] = x; tr[x].father = ff; tr[f].next[w] = s; tr[s].father = f; tr[x].next[not w] = f; tr[f].father = x; up(f); up(x); }
// splay 核心操作 inlinevoidsplay(int x, int tar){ for (int f = tr[x].father; f != tar; f = tr[x].father) { if (tr[f].father != tar) rotate(who(x) == who(f) ? f : x); rotate(x); } if (tar == 0) root = x; }
typedefint iter;
// 排名 rk 索引 iter kth(int rk, int tar){ int idx = root, cnt = 0; while (true) { done(idx); if (tr[tr[idx].next[0]].sum >= rk) { idx = tr[idx].next[0]; } else { rk -= tr[tr[idx].next[0]].sum + 1; if (rk <= 0) { splay(idx, tar); return idx; } idx = tr[idx].next[1]; } } }
// 建树, 过程保证数值与索引相等 voidbuild(int n){ for (int i = 1; i <= n; i++) { tr[cnt_tr - 1].next[1] = cnt_tr; tr[cnt_tr].father = cnt_tr - 1; cnt_tr++; } for (int i = cnt_tr - 1; i >= 1; i--) up(i); root = 1; cnt_tr = n + 1; }
// 导出答案 vector<int> out; voidwalk(int idx){ done(idx); if (tr[idx].next[0]) walk(tr[idx].next[0]); out.push_back(idx - 1); if (tr[idx].next[1]) walk(tr[idx].next[1]); }
voidsolve(){ int n, q; cin >> n >> q; build(n + 2); while (q--) { int l, r; cin >> l >> r; kth(l, 0); kth(r + 2, root); tr[tr[tr[root].next[1]].next[0]].lazy ^= true; } walk(root); for (int i = 1; i <= n; i++) cout << out[i] << ' '; cout << endl; }