diff --git a/BZOJ/3110/3110.cpp b/BZOJ/3110/3110.cpp new file mode 100644 index 00000000..4bb32d6a --- /dev/null +++ b/BZOJ/3110/3110.cpp @@ -0,0 +1,183 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +class SegmentTree { + private: + struct node { + int l, r; + int sum, tag; + node *lchild, *rchild; + + node(const int &_l = 0, const int &_r = 0) + : l(_l), r(_r), sum(0), tag(0), lchild(nullptr), rchild(nullptr) {} + + void pushup() { + sum = 0; + + if (lchild != nullptr) sum += lchild->sum; + if (rchild != nullptr) sum += rchild->sum; + } + + void pushdown() { + int mid = l + r >> 1; + + if (lchild == nullptr) lchild = new node(l, mid); + if (rchild == nullptr) rchild = new node(mid + 1, r); + + lchild->sum += (mid - l + 1) * tag; + lchild->tag += tag; + + rchild->sum += (r - mid) * tag; + rchild->tag += tag; + + tag = 0; + } + }; + + const int n; + node *root; + + void modify(node *&cur, int l, int r, int ql, int qr, int val) { + if (cur == nullptr) cur = new node(l, r); + + if (ql <= l && r <= qr) { + cur->sum += (r - l + 1) * val; + cur->tag += val; + + return; + } + + int mid = l + r >> 1; + + cur->pushdown(); + + if (ql <= mid) modify(cur->lchild, l, mid, ql, qr, val); + if (qr > mid) modify(cur->rchild, mid + 1, r, ql, qr, val); + + cur->pushup(); + } + + int query(node *cur, int l, int r, int ql, int qr) { + if (cur == nullptr) return 0; + if (ql <= l && r <= qr) return cur->sum; + + int mid = l + r >> 1, + res = 0; + + cur->pushdown(); + + if (ql <= mid) res += query(cur->lchild, l, mid, ql, qr); + if (qr > mid) res += query(cur->rchild, mid + 1, r, ql, qr); + + return res; + } + + public: + SegmentTree(const int &_n) + : n(_n), root(nullptr) {} + + void modify(int ql, int qr, int val) { + modify(root, 1, n, ql, qr, val); + } + + int query(int ql, int qr) { + return query(root, 1, n, ql, qr); + } +}; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n, m, cnt = 0; + std::vector> qs; + + cin >> n >> m; + + for (int i = 1, op, l, r, c; i <= m; i++) { + cin >> op >> l >> r >> c; + + if (op == 1) { + qs.emplace_back(op, l, r, c, -1); + } else { // op == 2 + qs.emplace_back(op, l, r, c, cnt++); + } + } + + std::vector ans(cnt); + SegmentTree tr(n); + + std::function> &, int, int)> solve = [&](const std::vector> &qs, int l, int r) -> void { + if (qs.empty()) return; + + if (l == r) { + for (auto o : qs) { + int op, id; + + std::tie(op, std::ignore, std::ignore, std::ignore, id) = o; + + if (op == 2) ans[id] = l; + } + + return; + } + + int mid = l + r >> 1; + std::vector> ql, qr; + std::vector cur(qs.size()); + + for (int i = 0; i < qs.size(); i++) { + int op, l, r, k; + + std::tie(op, l, r, k, std::ignore) = qs[i]; + + if (op == 1) { + if (k > mid) tr.modify(l, r, 1); + } else { // op == 2 + cur[i] = tr.query(l, r); + } + } + + for (int i = 0; i < qs.size(); i++) { + int op, l, r, k; + + std::tie(op, l, r, k, std::ignore) = qs[i]; + + if (op == 1 && k > mid) { + tr.modify(l, r, -1); + } + } + + for (int i = 0; i < qs.size(); i++) { + int op, l, r, k, id; + + std::tie(op, l, r, k, id) = qs[i]; + + if (op == 1) { + if (k <= mid) ql.emplace_back(qs[i]); + else qr.emplace_back(qs[i]); + } else { // op == 2 + if (cur[i] < k) { + ql.emplace_back(op, l, r, k - cur[i], id); + } else { + qr.emplace_back(qs[i]); + } + } + } + + solve(ql, l, mid); + solve(qr, mid + 1, r); + }; + + solve(qs, 0, n); + + for (int x : ans) cout << x << endl; + + return 0; +} diff --git a/BZOJ/3110/data/1.in b/BZOJ/3110/data/1.in new file mode 100644 index 00000000..8d74226c --- /dev/null +++ b/BZOJ/3110/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:954a74af194d5139944bbe5eebaf40ee0de32cd699ec8ed2530954f1c7c3ddd0 +size 1062060 diff --git a/BZOJ/3110/data/1.out b/BZOJ/3110/data/1.out new file mode 100644 index 00000000..3fc46a8d --- /dev/null +++ b/BZOJ/3110/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:22947ca08145aefc6c4119e6e1b98d8ddd9be8b7a2c750730e60106931a78e2b +size 216954 diff --git a/BZOJ/3110/data/10.in b/BZOJ/3110/data/10.in new file mode 100644 index 00000000..f7147f95 --- /dev/null +++ b/BZOJ/3110/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7e4ab57c3722598bfba6f57902a4dde5ac03632934648c40b1db1c2494c44ebc +size 794629 diff --git a/BZOJ/3110/data/10.out b/BZOJ/3110/data/10.out new file mode 100644 index 00000000..4211d4be --- /dev/null +++ b/BZOJ/3110/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a9a6dd4fe763b3a4933ec7bbab7699afe067c9c0068f5efcad45f817166fab5 +size 163184 diff --git a/BZOJ/3110/data/2.in b/BZOJ/3110/data/2.in new file mode 100644 index 00000000..53f5be0c --- /dev/null +++ b/BZOJ/3110/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5087c619aacdc8bcf4f0feff8c3d5171b0741fae66c26941b482a1fc9c97a9ed +size 728188 diff --git a/BZOJ/3110/data/2.out b/BZOJ/3110/data/2.out new file mode 100644 index 00000000..ef04d2a7 --- /dev/null +++ b/BZOJ/3110/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4c7f44e6ae9ea3256f74b3f0f227ee52d04ab40161b3927fd29a77d4e8fc263 +size 149296 diff --git a/BZOJ/3110/data/3.in b/BZOJ/3110/data/3.in new file mode 100644 index 00000000..ac777c70 --- /dev/null +++ b/BZOJ/3110/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c6eb367fe6a5aa36e1806f87b9046716103f08370ad47ce46972f389ae8c4f8 +size 661498 diff --git a/BZOJ/3110/data/3.out b/BZOJ/3110/data/3.out new file mode 100644 index 00000000..b10bebbd --- /dev/null +++ b/BZOJ/3110/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a2abe8c7a4d4cb2bf803d51f25c905b0b286b3b46496fd295a49198f4c43856 +size 136033 diff --git a/BZOJ/3110/data/4.in b/BZOJ/3110/data/4.in new file mode 100644 index 00000000..79721050 --- /dev/null +++ b/BZOJ/3110/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:74bd03922d15444dba77814c19de3190302e26378a7da178bf1b90b002d36db0 +size 861375 diff --git a/BZOJ/3110/data/4.out b/BZOJ/3110/data/4.out new file mode 100644 index 00000000..0e91da55 --- /dev/null +++ b/BZOJ/3110/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fe420f425a444ed70d6699d18962f695191a2607bee6da65ba27ecb72b630b95 +size 176732 diff --git a/BZOJ/3110/data/5.in b/BZOJ/3110/data/5.in new file mode 100644 index 00000000..a4621146 --- /dev/null +++ b/BZOJ/3110/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68a3e345f2ce35dd63731e9c7ce41c6e725dffd692c95879357e73d86e036814 +size 14449 diff --git a/BZOJ/3110/data/5.out b/BZOJ/3110/data/5.out new file mode 100644 index 00000000..fac768b5 --- /dev/null +++ b/BZOJ/3110/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b6f4b464a2e653fa2af92714d5f2c1155b007ca783b77e23e4e07ef478fad31 +size 2876 diff --git a/BZOJ/3110/data/6.in b/BZOJ/3110/data/6.in new file mode 100644 index 00000000..cbe06ec7 --- /dev/null +++ b/BZOJ/3110/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f8e9bf52d1515e91864a6b27a4733591cfd6caa27eb2b65bdc5bdada8bb3200 +size 994291 diff --git a/BZOJ/3110/data/6.out b/BZOJ/3110/data/6.out new file mode 100644 index 00000000..74dd1361 --- /dev/null +++ b/BZOJ/3110/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1041383795d4ee46feaa773a238e308f3917f47a2d8df4c6d99c3a1f8ff4b3be +size 204051 diff --git a/BZOJ/3110/data/7.in b/BZOJ/3110/data/7.in new file mode 100644 index 00000000..17154455 --- /dev/null +++ b/BZOJ/3110/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95749798d1069dc18f07501d6a4986f4ad6ce39bb34107fefbecd8a2338fc3c8 +size 927655 diff --git a/BZOJ/3110/data/7.out b/BZOJ/3110/data/7.out new file mode 100644 index 00000000..a6fed599 --- /dev/null +++ b/BZOJ/3110/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf79950c9ad0555dd99e6923f063e35975e1dda710b72eef4e28c48e31c9c33b +size 189996 diff --git a/BZOJ/3110/data/8.in b/BZOJ/3110/data/8.in new file mode 100644 index 00000000..110339d5 --- /dev/null +++ b/BZOJ/3110/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:30afa286a8c4cb8965e5447b940ac3da1dabfce28e224fe8f64cc7030dea570f +size 14431 diff --git a/BZOJ/3110/data/8.out b/BZOJ/3110/data/8.out new file mode 100644 index 00000000..bd407527 --- /dev/null +++ b/BZOJ/3110/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:950d45d27b26f1eb2b495394623a0a63e86f6147c659c5cdd5c469f75ef132a6 +size 2931 diff --git a/BZOJ/3110/data/9.in b/BZOJ/3110/data/9.in new file mode 100644 index 00000000..bb8b0e74 --- /dev/null +++ b/BZOJ/3110/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6697b950423cd48e5173498fcd7e0b5147732c70a16b08c808550e16f1608eb8 +size 14467 diff --git a/BZOJ/3110/data/9.out b/BZOJ/3110/data/9.out new file mode 100644 index 00000000..4a9ad1b1 --- /dev/null +++ b/BZOJ/3110/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:937bd40b5a9d1470e444173f58a61fcdd8b8fb82e580f62ce8aa585787321a88 +size 2816