#include <bits/stdc++.h> constexpr auto Inf = 0x3F3F3F3F; typedef long long LL; using namespace std; namespace IO { inline LL read() { LL o = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); } return o * f; } inline char recd() { char o; while ((o = getchar()) != 'Q' && o != 'A'); return o; } } using namespace IO; const int SIZE = 1E5 + 7; struct Node { int Re, w, sze, Fa, son[2]; } Node[SIZE]; int Tot, que, Root, now; inline void pushup(int now) { Node[now].sze = Node[Node[now].son[0]].sze + Node[Node[now].son[1]].sze + 1; } int BUILD(int F, int L, int R) { if (L > R) return 0; int M = (L + R) >> 1, pos = ++now; Node[pos].Fa = F; Node[pos].w = M; Node[pos].son[0] = BUILD(pos, L, M - 1); Node[pos].son[1] = BUILD(pos, M + 1, R); pushup(pos); return pos; } inline int which(int now) { return now == Node[Node[now].Fa].son[1]; } inline void pushdown(int now) { if (Node[now].Re) { Node[Node[now].son[0]].Re ^= 1; Node[Node[now].son[1]].Re ^= 1; swap(Node[now].son[0], Node[now].son[1]); Node[now].Re = 0; } } void Rot(int now) { int F = Node[now].Fa, FF = Node[F].Fa; int w = which(now); Node[F].son[w] = Node[now].son[!w]; Node[Node[now].son[!w]].Fa = F; Node[FF].son[which(F)] = now; Node[now].Fa = FF; Node[now].son[!w] = F; Node[F].Fa = now; pushup(F), pushup(now); } void Splay(int now, int pos) { while (Node[now].Fa != pos) { if (Node[Node[now].Fa].Fa != pos) which(Node[now].Fa) == which(now) ? Rot(now) : Rot(Node[now].Fa); Rot(now); } if (!pos) Root = now; } int Fnd(int w) { int pos = Root; w += 1; while (true) { pushdown(pos); if (Node[Node[pos].son[0]].sze >= w) pos = Node[pos].son[0]; else { w -= Node[Node[pos].son[0]].sze + 1; if (!w) return pos; pos = Node[pos].son[1]; } } return -1; } void Rev(int L, int R) { int posL = Fnd(L - 1), posR = Fnd(R + 1); Splay(posL, 0); Splay(posR, posL); Node[Node[Node[Root].son[1]].son[0]].Re ^= 1; } void DFS(int now) { pushdown(now); if (Node[now].son[0]) DFS(Node[now].son[0]); if (Node[now].w && Node[now].w != Tot + 1) cout << Node[now].w << ' '; if (Node[now].son[1]) DFS(Node[now].son[1]); } int main() { Tot = read(), que = read(); Root = BUILD(0, 0, Tot + 1); while (que--) { int L = read(), R = read(); Rev(L, R); } DFS(Root); }
0.0分
0 人评分