diff --git a/LibreOJ/105/105.cpp b/LibreOJ/105/105.cpp new file mode 100644 index 00000000..813c0a3e --- /dev/null +++ b/LibreOJ/105/105.cpp @@ -0,0 +1,105 @@ +#include +#include + +using std::cin; +using std::cout; +#define endl '\n' + +const int N = 1e5 + 5; + +int n, m, l, r, root, cnt; + +struct node { + int l, r, s, v, k; + bool d; + + node() + : l(0), r(0), s(0), v(0), d(false), k(rand()) {} + node(int _v) + : l(0), r(0), s(1), v(_v), d(false), k(rand()) {} +} tr[N]; + +void pushup(int u) { + tr[u].s = tr[tr[u].l].s + tr[tr[u].r].s + 1; +} + +void pushdown(int u) { + if (tr[u].d) { + tr[u].d = false; + tr[tr[u].l].d ^= 1; + tr[tr[u].r].d ^= 1; + std::swap(tr[u].l, tr[u].r); + } +} + +int build(int l, int r) { + if (l > r) return 0; + int mid = l + r >> 1; + int p = ++cnt; + tr[p] = node(mid - 1); + tr[p].l = build(l, mid - 1); + tr[p].r = build(mid + 1, r); + pushup(p); + return p; +} + +std::pair split(int p, int k) { + if (!p) return std::make_pair(0, 0); + pushdown(p); + if (k <= tr[tr[p].l].s) { + auto o = split(tr[p].l, k); + tr[p].l = o.second; + pushup(p); + o.second = p; + return o; + } + auto o = split(tr[p].r, k - tr[tr[p].l].s - 1); + tr[p].r = o.first; + pushup(p); + o.first = p; + return o; +} + +int merge(int x, int y) { + if (!x || !y) return x | y; + pushdown(x); + pushdown(y); + if (tr[x].k > tr[y].k) { + tr[x].r = merge(tr[x].r, y); + pushup(x); + return x; + } + tr[y].l = merge(x, tr[y].l); + pushup(y); + return y; +} + +void reserve(int l, int r) { + auto x = split(root, r + 1); + auto y = split(x.first, l); + tr[y.second].d ^= 1; + root = merge(merge(y.first, y.second), x.second); +} + +void print(int p) { + if (!p) return; + pushdown(p); + print(tr[p].l); + if (1 <= tr[p].v && tr[p].v <= n) { + cout << tr[p].v << ' '; + } + print(tr[p].r); +} + +int main() { + std::ios::sync_with_stdio(false); + cin >> n >> m; + root = build(1, n + 2); + while (m--) { + cin >> l >> r; + reserve(l, r); + } + print(root); + cout << endl; + return 0; +} diff --git a/LibreOJ/105/data/input0.in b/LibreOJ/105/data/input0.in new file mode 100644 index 00000000..8a94ab4a --- /dev/null +++ b/LibreOJ/105/data/input0.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc7a2190939257e673815afcffff31989e6cf882ce023b82087222952e6fd7a4 +size 29 diff --git a/LibreOJ/105/data/input0.out b/LibreOJ/105/data/input0.out new file mode 100644 index 00000000..e17077ca --- /dev/null +++ b/LibreOJ/105/data/input0.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8280dab097a39e2b761a25bf154e904227db88a498cea8f3593329a6f957eb2 +size 81 diff --git a/LibreOJ/105/data/input1.in b/LibreOJ/105/data/input1.in new file mode 100644 index 00000000..5c782ab1 --- /dev/null +++ b/LibreOJ/105/data/input1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32733303bdfb72e2594f8fb638a8761888a43f37e73423e98f46f291ce16c1ff +size 63 diff --git a/LibreOJ/105/data/input1.out b/LibreOJ/105/data/input1.out new file mode 100644 index 00000000..5ec18bf8 --- /dev/null +++ b/LibreOJ/105/data/input1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:630d1bc50ea9a9b9006f62fe42eb7e17b24425652f49d7f3bd730ce15aeeca30 +size 292 diff --git a/LibreOJ/105/data/input2.in b/LibreOJ/105/data/input2.in new file mode 100644 index 00000000..ed77ba55 --- /dev/null +++ b/LibreOJ/105/data/input2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:698b3499d981de05445d2ae041248515248b8bc62bfa4dc1c88348dad62f008e +size 346 diff --git a/LibreOJ/105/data/input2.out b/LibreOJ/105/data/input2.out new file mode 100644 index 00000000..e1db5d3a --- /dev/null +++ b/LibreOJ/105/data/input2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14b78d6ed78981d48105f8b56e8afe820fb4168ee283307c5bafeee42eead58a +size 692 diff --git a/LibreOJ/105/data/input3.in b/LibreOJ/105/data/input3.in new file mode 100644 index 00000000..f8e05789 --- /dev/null +++ b/LibreOJ/105/data/input3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e09f17293255275964331541865df038297dacbab156b2c345c1417c261b9e5 +size 336 diff --git a/LibreOJ/105/data/input3.out b/LibreOJ/105/data/input3.out new file mode 100644 index 00000000..fae0ba74 --- /dev/null +++ b/LibreOJ/105/data/input3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1aeea9cdd7100bdd10e42631b94ff93801e0bcb933357358bb8cb9095a8a44d +size 692 diff --git a/LibreOJ/105/data/input4.in b/LibreOJ/105/data/input4.in new file mode 100644 index 00000000..24fef18f --- /dev/null +++ b/LibreOJ/105/data/input4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:61388606db02e5019f219338e2b4dd6323164113107300639095f5275a849935 +size 29087 diff --git a/LibreOJ/105/data/input4.out b/LibreOJ/105/data/input4.out new file mode 100644 index 00000000..af0917db --- /dev/null +++ b/LibreOJ/105/data/input4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:914c1e3e312c3e167bd54e301bc72d82022256da91a45203a07059e8a9915f1b +size 48894 diff --git a/LibreOJ/105/data/input5.in b/LibreOJ/105/data/input5.in new file mode 100644 index 00000000..1c1b9323 --- /dev/null +++ b/LibreOJ/105/data/input5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4fa5cfe8cbae862d289f7c59534a70fe3229c18c7b39246d9ddb491ef32325a0 +size 569265 diff --git a/LibreOJ/105/data/input5.out b/LibreOJ/105/data/input5.out new file mode 100644 index 00000000..cf995e0d --- /dev/null +++ b/LibreOJ/105/data/input5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab171e800f806c0a5f551921d7e79ba04057394ef9188e2340ea421a9222bb6c +size 288894 diff --git a/LibreOJ/105/data/input6.in b/LibreOJ/105/data/input6.in new file mode 100644 index 00000000..e606ddc0 --- /dev/null +++ b/LibreOJ/105/data/input6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3270ce218dab531b2c37a279e5f5ebfd574826b3164cf23b916d1694be1a28f9 +size 813303 diff --git a/LibreOJ/105/data/input6.out b/LibreOJ/105/data/input6.out new file mode 100644 index 00000000..e54ca5b1 --- /dev/null +++ b/LibreOJ/105/data/input6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:26bf03f5142e1717c0c071a84a96d06cd4ea256a90fe2d4df5c28c4f4b9b9271 +size 468894 diff --git a/LibreOJ/105/data/input7.in b/LibreOJ/105/data/input7.in new file mode 100644 index 00000000..2394f101 --- /dev/null +++ b/LibreOJ/105/data/input7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed3e50b799569b1aae18abd8b7d69b6fa5dc7ce553015998c5e50f5f6a5c99c9 +size 1169441 diff --git a/LibreOJ/105/data/input7.out b/LibreOJ/105/data/input7.out new file mode 100644 index 00000000..21ef8c89 --- /dev/null +++ b/LibreOJ/105/data/input7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dba28d66cb973cbfaa0c7c0bb1e24716f26ab05efe2b7f148175c6024d24ab2f +size 588895 diff --git a/LibreOJ/105/data/input8.in b/LibreOJ/105/data/input8.in new file mode 100644 index 00000000..2b06580b --- /dev/null +++ b/LibreOJ/105/data/input8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:534b814fcfbc982770ba39bb6dd0b3cbc0b09283efd59720fd2344dca0e032f3 +size 1169128 diff --git a/LibreOJ/105/data/input8.out b/LibreOJ/105/data/input8.out new file mode 100644 index 00000000..49480f65 --- /dev/null +++ b/LibreOJ/105/data/input8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9c42bdb6dff64c54b5c678aea74c26fe4ab68baa6d37a0fc49cc8763aceebdaf +size 588895 diff --git a/LibreOJ/105/data/input9.in b/LibreOJ/105/data/input9.in new file mode 100644 index 00000000..45af7d81 --- /dev/null +++ b/LibreOJ/105/data/input9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46fa7973e877781b3b56413e0b8b71c1004e2dab5b523bd5a37d0b6e58778f57 +size 1169131 diff --git a/LibreOJ/105/data/input9.out b/LibreOJ/105/data/input9.out new file mode 100644 index 00000000..4d16b53b --- /dev/null +++ b/LibreOJ/105/data/input9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:768193c903cd06ff9bbe40bc18be2ede778a113eccbba3d96baee3556243d799 +size 588895