diff --git a/BZOJ/1901/1901.cpp b/BZOJ/1901/1901.cpp new file mode 100644 index 00000000..dfc9b19f --- /dev/null +++ b/BZOJ/1901/1901.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, m, a[N], c[N], ans[N]; + +inline int lowbit(int x) { + return x & -x; +} + +inline void add(int x, int y) { + for (; x <= n; x += lowbit(x)) c[x] += y; +} + +inline int sum(int x) { + int ret = 0; + for (; x > 0; x -= lowbit(x)) ret += c[x]; + return ret; +} + +void solve(int l, int r, const std::vector>& q) { + if (q.empty()) return; + + if (r - l == 1) { + for (const auto& x : q) { + if (std::get<0>(x) == 'Q') { + ans[std::get<4>(x)] = l; + } + } + + return; + } + + int mid = l + r >> 1; + std::vector> left, right; + + for (const auto& e : q) { + char op; + int x, y, z, id; + + std::tie(op, x, y, z, id) = e; + + if (op == 'Q') { + int k = sum(y) - sum(x - 1); + + if (k >= z) { + left.push_back(e); + } else { + z -= k; + right.emplace_back(op, x, y, z, id); + } + } else { // op == 'C' + if (y < mid) { + add(x, z); + left.push_back(e); + } else { + right.push_back(e); + } + } + } + + for (const auto& e : left) { + char op; + int x, y, z, id; + + std::tie(op, x, y, z, id) = e; + + if (op == 'C') { + add(x, -z); + } + } + + solve(l, mid, left); + solve(mid, r, right); +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + memset(ans, 0xff, sizeof(ans)); + + cin >> n >> m; + + std::vector> q; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + + q.emplace_back('C', i, a[i], 1, 0); + } + + for (int i = 1; i <= m; i++) { + char op; + int x, y, z; + + cin >> op >> x >> y; + + if (op == 'Q') { + cin >> z; + + q.emplace_back('Q', x, y, z, i); + } else { // op == 'C' + q.emplace_back('C', x, a[x], -1, 0); + a[x] = y; + q.emplace_back('C', x, y, 1, 0); + } + } + + solve(0, 1e9, q); + + for (int i = 1; i <= m; i++) { + if (~ans[i]) { + cout << ans[i] << endl; + } + } + + return 0; +} diff --git a/BZOJ/1901/data/1.in b/BZOJ/1901/data/1.in new file mode 100644 index 00000000..56707e8d --- /dev/null +++ b/BZOJ/1901/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a91484c96682c46b6fa43c68d1cc5e4a9574f314fcf4da7c1b98a9c353ecbd6 +size 190452 diff --git a/BZOJ/1901/data/1.out b/BZOJ/1901/data/1.out new file mode 100644 index 00000000..274d97e1 --- /dev/null +++ b/BZOJ/1901/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93a8c6b1e02f76ed2216f8a5b975bb741eed53882cd03abd21cd56effc5a4779 +size 41308 diff --git a/BZOJ/1901/data/10.in b/BZOJ/1901/data/10.in new file mode 100644 index 00000000..04257c5a --- /dev/null +++ b/BZOJ/1901/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:283450ff6c459111f66a3f2899fa81014d69abed7aabbfe6635484f884365415 +size 99386 diff --git a/BZOJ/1901/data/10.out b/BZOJ/1901/data/10.out new file mode 100644 index 00000000..f9962c52 --- /dev/null +++ b/BZOJ/1901/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd7a927c29458d910b3d9f8d234f4f68bb7b514b5847b28b7d88c5357faf9eb2 +size 25220 diff --git a/BZOJ/1901/data/2.in b/BZOJ/1901/data/2.in new file mode 100644 index 00000000..ec20c2fd --- /dev/null +++ b/BZOJ/1901/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cadaaf68ab8419607b48170a4704b5ef4d64d325a4b8814b2ac8d708b79afa90 +size 13950 diff --git a/BZOJ/1901/data/2.out b/BZOJ/1901/data/2.out new file mode 100644 index 00000000..89ae215b --- /dev/null +++ b/BZOJ/1901/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:252663c4536b1749c93197fc09cdb91e2b499fb99dc33d97100776c033ca8e27 +size 3555 diff --git a/BZOJ/1901/data/3.in b/BZOJ/1901/data/3.in new file mode 100644 index 00000000..2a86b3a9 --- /dev/null +++ b/BZOJ/1901/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32dd312f6e551753a92106fc8ade39745b7a89502ac19424f251465e1f22d1af +size 170358 diff --git a/BZOJ/1901/data/3.out b/BZOJ/1901/data/3.out new file mode 100644 index 00000000..56c3d24f --- /dev/null +++ b/BZOJ/1901/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:230df33a2497dfc30f4ce91fe94e630c61cfe299757bc18fe8bd9fea3939f0c0 +size 43403 diff --git a/BZOJ/1901/data/4.in b/BZOJ/1901/data/4.in new file mode 100644 index 00000000..ae2a8073 --- /dev/null +++ b/BZOJ/1901/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:478dfd7fb0173b90a7678ad09d07c2175a4950753a8febb4aa4f4e1199e58b8a +size 788 diff --git a/BZOJ/1901/data/4.out b/BZOJ/1901/data/4.out new file mode 100644 index 00000000..c1110fc6 --- /dev/null +++ b/BZOJ/1901/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf55d0e74c99cfed78bc9566b8c6a71db38ef030cee6131934d83ded7277b99b +size 148 diff --git a/BZOJ/1901/data/5.in b/BZOJ/1901/data/5.in new file mode 100644 index 00000000..7382b294 --- /dev/null +++ b/BZOJ/1901/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66c77b543f3e5f9adf05c7a9a38886ff1fd9402e383ce0c33fc9aaaf133bc321 +size 21458 diff --git a/BZOJ/1901/data/5.out b/BZOJ/1901/data/5.out new file mode 100644 index 00000000..511f4be8 --- /dev/null +++ b/BZOJ/1901/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c448f9021e3d4a0f5b7a98fac71a7090a1478a1a0096c75945c44bdef3487b7 +size 7594 diff --git a/BZOJ/1901/data/6.in b/BZOJ/1901/data/6.in new file mode 100644 index 00000000..2a0b36a2 --- /dev/null +++ b/BZOJ/1901/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d1778e33b55a0da2d9bc7ee67ae78d9891ae7616a89caaaad9fc335a59f2217 +size 200524 diff --git a/BZOJ/1901/data/6.out b/BZOJ/1901/data/6.out new file mode 100644 index 00000000..51e75f42 --- /dev/null +++ b/BZOJ/1901/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7a34e709633ec9fd99afd789fbb6d5ea06aa2f19e5fddab64ba9911db1f30a5 +size 29287 diff --git a/BZOJ/1901/data/7.in b/BZOJ/1901/data/7.in new file mode 100644 index 00000000..794cf005 --- /dev/null +++ b/BZOJ/1901/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:03e5986ba59ad3061e5d68818ea4d977760a953ba67fc6b6ef140dd6cda4a54b +size 820 diff --git a/BZOJ/1901/data/7.out b/BZOJ/1901/data/7.out new file mode 100644 index 00000000..02fd63f9 --- /dev/null +++ b/BZOJ/1901/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0144803cc89b0e52d2c814a847523b333e327c5ceaa3fada64b4a2cf777ae872 +size 61 diff --git a/BZOJ/1901/data/8.in b/BZOJ/1901/data/8.in new file mode 100644 index 00000000..3a96337f --- /dev/null +++ b/BZOJ/1901/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab2506a1a8807b6c8eb3ee826703982ffe1e94cfe99715e8187c11ca8193ebad +size 167018 diff --git a/BZOJ/1901/data/8.out b/BZOJ/1901/data/8.out new file mode 100644 index 00000000..1ba5db52 --- /dev/null +++ b/BZOJ/1901/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c429b80e5f45c1ec57c693ccacb4a2c0948f2c6aacbec0eeb7e96f560152317 +size 42711 diff --git a/BZOJ/1901/data/9.in b/BZOJ/1901/data/9.in new file mode 100644 index 00000000..930d6849 --- /dev/null +++ b/BZOJ/1901/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8081f41eb3ccf5673e54afad356194069cc190b2a4af5f40f47c093450814bf4 +size 261104 diff --git a/BZOJ/1901/data/9.out b/BZOJ/1901/data/9.out new file mode 100644 index 00000000..2a5643a4 --- /dev/null +++ b/BZOJ/1901/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1fbd125efe39080b452ed1c1a23ad7a4d61876fca4ae59b236ebb4748f19134f +size 96127