From 54ba889e6463dd5b20c2715dfd19f4d358abf062 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 31 May 2022 20:23:39 +0800 Subject: [PATCH] =?UTF-8?q?#10145.=20=E3=80=8C=E4=B8=80=E6=9C=AC=E9=80=9A?= =?UTF-8?q?=204.6=20=E7=BB=83=E4=B9=A0=202=E3=80=8D=E9=83=81=E9=97=B7?= =?UTF-8?q?=E7=9A=84=E5=87=BA=E7=BA=B3=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1472998 --- LibreOJ/10145/10145.cpp | 130 +++++++++++++++++++++++++++++++ LibreOJ/10145/data/cashier.bat | 3 + LibreOJ/10145/data/cashier1.ans | 3 + LibreOJ/10145/data/cashier1.in | 3 + LibreOJ/10145/data/cashier10.ans | 3 + LibreOJ/10145/data/cashier10.in | 3 + LibreOJ/10145/data/cashier2.ans | 3 + LibreOJ/10145/data/cashier2.in | 3 + LibreOJ/10145/data/cashier3.ans | 3 + LibreOJ/10145/data/cashier3.in | 3 + LibreOJ/10145/data/cashier4.ans | 3 + LibreOJ/10145/data/cashier4.in | 3 + LibreOJ/10145/data/cashier5.ans | 3 + LibreOJ/10145/data/cashier5.in | 3 + LibreOJ/10145/data/cashier6.ans | 3 + LibreOJ/10145/data/cashier6.in | 3 + LibreOJ/10145/data/cashier7.ans | 3 + LibreOJ/10145/data/cashier7.in | 3 + LibreOJ/10145/data/cashier8.ans | 3 + LibreOJ/10145/data/cashier8.in | 3 + LibreOJ/10145/data/cashier9.ans | 3 + LibreOJ/10145/data/cashier9.in | 3 + 22 files changed, 193 insertions(+) create mode 100644 LibreOJ/10145/10145.cpp create mode 100644 LibreOJ/10145/data/cashier.bat create mode 100644 LibreOJ/10145/data/cashier1.ans create mode 100644 LibreOJ/10145/data/cashier1.in create mode 100644 LibreOJ/10145/data/cashier10.ans create mode 100644 LibreOJ/10145/data/cashier10.in create mode 100644 LibreOJ/10145/data/cashier2.ans create mode 100644 LibreOJ/10145/data/cashier2.in create mode 100644 LibreOJ/10145/data/cashier3.ans create mode 100644 LibreOJ/10145/data/cashier3.in create mode 100644 LibreOJ/10145/data/cashier4.ans create mode 100644 LibreOJ/10145/data/cashier4.in create mode 100644 LibreOJ/10145/data/cashier5.ans create mode 100644 LibreOJ/10145/data/cashier5.in create mode 100644 LibreOJ/10145/data/cashier6.ans create mode 100644 LibreOJ/10145/data/cashier6.in create mode 100644 LibreOJ/10145/data/cashier7.ans create mode 100644 LibreOJ/10145/data/cashier7.in create mode 100644 LibreOJ/10145/data/cashier8.ans create mode 100644 LibreOJ/10145/data/cashier8.in create mode 100644 LibreOJ/10145/data/cashier9.ans create mode 100644 LibreOJ/10145/data/cashier9.in diff --git a/LibreOJ/10145/10145.cpp b/LibreOJ/10145/10145.cpp new file mode 100644 index 00000000..9a54ca33 --- /dev/null +++ b/LibreOJ/10145/10145.cpp @@ -0,0 +1,130 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, min, k, c, ans; +char op; + +// Treap + +int root, cnt; + +struct node { + int l, r, s, v, k; + + node() + : l(0), r(0), s(0), v(0), k(rand()) {} + + node(int _v) + : l(0), r(0), s(1), v(_v), k(rand()) {} +} tr[N]; + +void pushup(int u) { + tr[u].s = tr[tr[u].l].s + 1 + tr[tr[u].r].s; +} + +std::pair split(int p, int k) { + if (!p) return std::make_pair(0, 0); + + 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; +} + +std::pair splitByValue(int p, int v) { + if (!p) return std::make_pair(0, 0); + + if (v <= tr[p].v) { + auto o = splitByValue(tr[p].l, v); + tr[p].l = o.second; + pushup(p); + o.second = p; + return o; + } + + auto o = splitByValue(tr[p].r, v); + tr[p].r = o.first; + pushup(p); + o.first = p; + + return o; +} + +int merge(int x, int y) { + if (!x || !y) return x | 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 insert(int v) { + auto o = splitByValue(root, v); + int p = ++cnt; + + tr[p] = node(v); + + root = merge(o.first, merge(p, o.second)); +} + +int getKth(int k) { + auto x = split(root, k - 1); + auto y = split(x.second, 1); + + int r = y.first; + + root = merge(x.first, merge(y.first, y.second)); + + return tr[r].v; +} + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n >> min; + + while (n--) { + cin >> op >> k; + + if (op == 'I') { + if (k >= min) { + insert(k - c); + } + } else if (op == 'A') { + c += k; + } else if (op == 'S') { + c -= k; + auto o = splitByValue(root, min - c); + root = o.second; + ans += tr[o.first].s; + } else { // op == 'F' + cout << (tr[root].s < k ? -1 : getKth(tr[root].s - k + 1) + c) << endl; + } + } + + cout << ans << endl; + + return 0; +} diff --git a/LibreOJ/10145/data/cashier.bat b/LibreOJ/10145/data/cashier.bat new file mode 100644 index 00000000..3c98abad --- /dev/null +++ b/LibreOJ/10145/data/cashier.bat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79eb3e9a7d6230b323f0769a5569d89ae0b4933a480a67ac3f51696cb7a25682 +size 280 diff --git a/LibreOJ/10145/data/cashier1.ans b/LibreOJ/10145/data/cashier1.ans new file mode 100644 index 00000000..04f88de0 --- /dev/null +++ b/LibreOJ/10145/data/cashier1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdd52aadde7ad0ed29c7aeb06393150a42ceebda386179c18b1b13843565b8b1 +size 20 diff --git a/LibreOJ/10145/data/cashier1.in b/LibreOJ/10145/data/cashier1.in new file mode 100644 index 00000000..546b03ad --- /dev/null +++ b/LibreOJ/10145/data/cashier1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a14deca652b53722ad6040c0ec37f20407e471c2dea6262ec132f245ebbd2b97 +size 107 diff --git a/LibreOJ/10145/data/cashier10.ans b/LibreOJ/10145/data/cashier10.ans new file mode 100644 index 00000000..73523bfe --- /dev/null +++ b/LibreOJ/10145/data/cashier10.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7a2acccc182d01bff21e14dc663ea3e3be096a3105f19853622fc2a574208a6f +size 525643 diff --git a/LibreOJ/10145/data/cashier10.in b/LibreOJ/10145/data/cashier10.in new file mode 100644 index 00000000..4b275657 --- /dev/null +++ b/LibreOJ/10145/data/cashier10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73a1ec07842c22deabfe90595d4584d3dacc0ee2a8b17f7ec0f86c2a96e1413b +size 1407178 diff --git a/LibreOJ/10145/data/cashier2.ans b/LibreOJ/10145/data/cashier2.ans new file mode 100644 index 00000000..2bef163d --- /dev/null +++ b/LibreOJ/10145/data/cashier2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f575f917684bb6dd20110db53b95bcdab4304401b7a27d242e21fb8b52afd5c2 +size 862 diff --git a/LibreOJ/10145/data/cashier2.in b/LibreOJ/10145/data/cashier2.in new file mode 100644 index 00000000..37d8c652 --- /dev/null +++ b/LibreOJ/10145/data/cashier2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:485e41187472f11757efdc9bada0607cb0a913f150f7509d31dd9f47fa472e53 +size 2009 diff --git a/LibreOJ/10145/data/cashier3.ans b/LibreOJ/10145/data/cashier3.ans new file mode 100644 index 00000000..0c69759d --- /dev/null +++ b/LibreOJ/10145/data/cashier3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:372d7752de10e6c4f5eebab11653fa26d0a3fe9e9f632c7c23801cce71fdeb60 +size 2427 diff --git a/LibreOJ/10145/data/cashier3.in b/LibreOJ/10145/data/cashier3.in new file mode 100644 index 00000000..d885b98d --- /dev/null +++ b/LibreOJ/10145/data/cashier3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b2dd04bff020798f41befeb3adf3f672c84146cc554370bad110b744a0f431a +size 72776 diff --git a/LibreOJ/10145/data/cashier4.ans b/LibreOJ/10145/data/cashier4.ans new file mode 100644 index 00000000..393ee659 --- /dev/null +++ b/LibreOJ/10145/data/cashier4.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:06fc61ec37ad54368346fc5d958c2a685547efbf2a77089eed39859c3458f4a5 +size 58849 diff --git a/LibreOJ/10145/data/cashier4.in b/LibreOJ/10145/data/cashier4.in new file mode 100644 index 00000000..69f2805a --- /dev/null +++ b/LibreOJ/10145/data/cashier4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27c7e53e2e28cf6025d62539ca11c38081bd26c44fc79769e31b2e3c2d679600 +size 240011 diff --git a/LibreOJ/10145/data/cashier5.ans b/LibreOJ/10145/data/cashier5.ans new file mode 100644 index 00000000..7b21bc45 --- /dev/null +++ b/LibreOJ/10145/data/cashier5.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47637306d9752f6a74f31a8133280f27a82dc8758dc72d12117d6dfd534479f7 +size 134367 diff --git a/LibreOJ/10145/data/cashier5.in b/LibreOJ/10145/data/cashier5.in new file mode 100644 index 00000000..c14d1d4b --- /dev/null +++ b/LibreOJ/10145/data/cashier5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79b20ce6db0369ebbdb112d3fd7be2d1df16529418156939ac414e14228cd80c +size 432189 diff --git a/LibreOJ/10145/data/cashier6.ans b/LibreOJ/10145/data/cashier6.ans new file mode 100644 index 00000000..2f7f9fad --- /dev/null +++ b/LibreOJ/10145/data/cashier6.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d699752ce87b3679513f694ce411d72175e83cdd9403760fa3dbdd1714f92dc +size 131396 diff --git a/LibreOJ/10145/data/cashier6.in b/LibreOJ/10145/data/cashier6.in new file mode 100644 index 00000000..433c7ba8 --- /dev/null +++ b/LibreOJ/10145/data/cashier6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59bada5603e78e7727ab99af5db1936ce67e4a026e39ba91c15d12f6c131839e +size 612417 diff --git a/LibreOJ/10145/data/cashier7.ans b/LibreOJ/10145/data/cashier7.ans new file mode 100644 index 00000000..e62c14ca --- /dev/null +++ b/LibreOJ/10145/data/cashier7.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59cc251af45bba0df1497a6b1a0530db54cbd4df4e189d94d31223c98174b486 +size 66479 diff --git a/LibreOJ/10145/data/cashier7.in b/LibreOJ/10145/data/cashier7.in new file mode 100644 index 00000000..b0112015 --- /dev/null +++ b/LibreOJ/10145/data/cashier7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32527da6b91c66dc27524670dfe5f98a4e17895e079811e8281b22a4a42b64d4 +size 529035 diff --git a/LibreOJ/10145/data/cashier8.ans b/LibreOJ/10145/data/cashier8.ans new file mode 100644 index 00000000..9e377b2b --- /dev/null +++ b/LibreOJ/10145/data/cashier8.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41213e01f24eb54a21a670d69b516eb12e2634b26eba27e3fd9f37a844385048 +size 333374 diff --git a/LibreOJ/10145/data/cashier8.in b/LibreOJ/10145/data/cashier8.in new file mode 100644 index 00000000..629ea466 --- /dev/null +++ b/LibreOJ/10145/data/cashier8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59e5b53cbf9c3d280a64171e006bc31bb0bc70f1e5c441762227df455043b5e7 +size 1139894 diff --git a/LibreOJ/10145/data/cashier9.ans b/LibreOJ/10145/data/cashier9.ans new file mode 100644 index 00000000..4f1c5ee7 --- /dev/null +++ b/LibreOJ/10145/data/cashier9.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8baadc0a4c607c44d981a966285e349383dc48add5490851fc21ed82f3e2858c +size 524152 diff --git a/LibreOJ/10145/data/cashier9.in b/LibreOJ/10145/data/cashier9.in new file mode 100644 index 00000000..9d5a559a --- /dev/null +++ b/LibreOJ/10145/data/cashier9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3249a8a4977a209e304db80a5fef5f2f924468f22fd37e3676e6b41106a4c632 +size 1586396