diff --git a/LibreOJ/2055/2055.cpp b/LibreOJ/2055/2055.cpp new file mode 100644 index 00000000..80bbf8a3 --- /dev/null +++ b/LibreOJ/2055/2055.cpp @@ -0,0 +1,199 @@ +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +template +class SegmentTree { + private: + struct node { + int l, r; + T sum, tag; + node *lchild, *rchild; + + node(const int &_l = 0, const int &_r = 0) + : l(_l), r(_r), sum(0), tag(-1), lchild(nullptr), rchild(nullptr) {} + + ~node() { + if (lchild) delete lchild; + if (rchild) delete rchild; + } + + void pushup() { + sum = 0; + + if (lchild != nullptr) sum += lchild->sum; + if (rchild != nullptr) sum += rchild->sum; + } + + void pushdown() { + if (tag == -1) return; + + int mid = (l + r) >> 1; + + if (lchild == nullptr) lchild = new node(l, mid); + if (rchild == nullptr) rchild = new node(mid + 1, r); + + lchild->sum = static_cast(lchild->r - lchild->l + 1) * tag; + lchild->tag = tag; + + rchild->sum = static_cast(rchild->r - rchild->l + 1) * tag; + rchild->tag = tag; + + tag = -1; + } + }; + + const int n; + node *root; + + void modify(node *&cur, int l, int r, int ql, int qr, T val) { + if (cur == nullptr) cur = new node(l, r); + + if (ql <= l && r <= qr) { + cur->sum = static_cast(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(); + } + + T query(node *cur, int l, int r, int ql, int qr) { + if (cur == nullptr) return T(); + if (ql <= l && r <= qr) return cur->sum; + + int mid = (l + r) >> 1; + T 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) {} + + SegmentTree(const std::vector &vec) + : n(vec.size()), root(nullptr) { + std::function build = [&](node *&cur, int l, int r) { + cur = new node(l, r); + + if (l == r) { + cur->sum = vec[l - 1]; + + return; + } + + int mid = (l + r) >> 1; + + build(cur->lchild, l, mid); + build(cur->rchild, mid + 1, r); + + cur->pushup(); + }; + + build(root, 1, n); + } + + ~SegmentTree() { + if (root) delete root; + } + + void modify(int ql, int qr, T val) { + if (ql > qr) return; + + modify(root, 1, n, ql, qr, val); + } + + T query(int ql, int qr) { + if (ql > qr) return T(); + + return query(root, 1, n, ql, qr); + } +}; + +int n, m, q, a[N]; +std::tuple qs[N]; + +bool check(int x) { + std::vector vec; + + std::transform(a + 1, a + 1 + n, std::back_inserter(vec), std::bind(std::greater_equal<>(), std::placeholders::_1, x)); + + SegmentTree tr(vec); + + for (int i = 1; i <= m; i++) { + int op, l, r; + + std::tie(op, l, r) = qs[i]; + + int cnt = tr.query(l, r); + + if (op == 0) { + tr.modify(r - cnt + 1, r, 1); + tr.modify(l, r - cnt, 0); + } else { // op == 1 + tr.modify(l, l + cnt - 1, 1); + tr.modify(l + cnt, r, 0); + } + } + + return tr.query(q, q) == 1; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + for (int i = 1; i <= m; i++) { + cin >> std::get<0>(qs[i]) >> std::get<1>(qs[i]) >> std::get<2>(qs[i]); + } + + cin >> q; + + int l = 1, + r = n, + res = 0; + + while (l <= r) { + int mid = l + r >> 1; + + if (check(mid)) { + res = mid; + l = mid + 1; + } else { + r = mid - 1; + } + } + + cout << res << endl; + + return 0; +} diff --git a/LibreOJ/2055/data/sort1.in b/LibreOJ/2055/data/sort1.in new file mode 100644 index 00000000..3c12be9e --- /dev/null +++ b/LibreOJ/2055/data/sort1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2cc9539e015710d130566ef60fad8aeb5bac685d61bad14ef9c41e5e1efe4f7 +size 1090 diff --git a/LibreOJ/2055/data/sort1.out b/LibreOJ/2055/data/sort1.out new file mode 100644 index 00000000..45e3109e --- /dev/null +++ b/LibreOJ/2055/data/sort1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:606b7d0891b4db74edb21c241c302f298bf6ca4a6158deca6b58c15c950ab5f2 +size 3 diff --git a/LibreOJ/2055/data/sort10.in b/LibreOJ/2055/data/sort10.in new file mode 100644 index 00000000..35128679 --- /dev/null +++ b/LibreOJ/2055/data/sort10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7293a61c7e728943fc17ecb2571e7e5bc8e75207f074a136d1e6921bd3d28660 +size 1921561 diff --git a/LibreOJ/2055/data/sort10.out b/LibreOJ/2055/data/sort10.out new file mode 100644 index 00000000..b7a62e7c --- /dev/null +++ b/LibreOJ/2055/data/sort10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:359654a186bae130bd44debfb619a2e1e2c9a5cdc6fd843b28d2957608a22fc2 +size 7 diff --git a/LibreOJ/2055/data/sort2.in b/LibreOJ/2055/data/sort2.in new file mode 100644 index 00000000..c2f7c8ee --- /dev/null +++ b/LibreOJ/2055/data/sort2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e10937c56743a19aabb7e71dcae2259dd4ecefb976498d6aa4d1f66bbdd4105 +size 1089 diff --git a/LibreOJ/2055/data/sort2.out b/LibreOJ/2055/data/sort2.out new file mode 100644 index 00000000..bf7021d6 --- /dev/null +++ b/LibreOJ/2055/data/sort2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6c21e8d260fe71882debdb339d2402a2ca7648529bc2303f48649bce0380017 +size 3 diff --git a/LibreOJ/2055/data/sort3.in b/LibreOJ/2055/data/sort3.in new file mode 100644 index 00000000..8d214977 --- /dev/null +++ b/LibreOJ/2055/data/sort3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7fa13cc6dc5263a63ec9db10d35e7d584c04304ad9bdfb045c2896624a70c5ae +size 1092 diff --git a/LibreOJ/2055/data/sort3.out b/LibreOJ/2055/data/sort3.out new file mode 100644 index 00000000..8962e2ae --- /dev/null +++ b/LibreOJ/2055/data/sort3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e2ae11dad0616f66bbb2b6e6556f580bb987fd911d7132aa6bee2bfc7cc7b52 +size 3 diff --git a/LibreOJ/2055/data/sort4.in b/LibreOJ/2055/data/sort4.in new file mode 100644 index 00000000..46ac39c8 --- /dev/null +++ b/LibreOJ/2055/data/sort4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55625d7f3d6f6a7e1070f67252c82cb2db1e1fe6a378d7699a247b576799592d +size 296569 diff --git a/LibreOJ/2055/data/sort4.out b/LibreOJ/2055/data/sort4.out new file mode 100644 index 00000000..6e2bedef --- /dev/null +++ b/LibreOJ/2055/data/sort4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a20ea7a9868b11e0b2d2598a69e5310b973fd667909f89f9c7c4bbf0144b3ed3 +size 5 diff --git a/LibreOJ/2055/data/sort5.in b/LibreOJ/2055/data/sort5.in new file mode 100644 index 00000000..b1c58d50 --- /dev/null +++ b/LibreOJ/2055/data/sort5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81cf6995418c505451f1869dacb0c7f3f5c1411f5f0fcafb8893b2d68f009ea1 +size 365739 diff --git a/LibreOJ/2055/data/sort5.out b/LibreOJ/2055/data/sort5.out new file mode 100644 index 00000000..a388a067 --- /dev/null +++ b/LibreOJ/2055/data/sort5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67caee91d5777c4e0e895940c57139b0609ea273b51741a551bc9a2cd0869b5b +size 6 diff --git a/LibreOJ/2055/data/sort6.in b/LibreOJ/2055/data/sort6.in new file mode 100644 index 00000000..962f8ade --- /dev/null +++ b/LibreOJ/2055/data/sort6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d1daad7d566722a3cb1b0d2d3b2685841f4dfc2c9c89836723a274e1f98613f +size 88910 diff --git a/LibreOJ/2055/data/sort6.out b/LibreOJ/2055/data/sort6.out new file mode 100644 index 00000000..4ba8ed65 --- /dev/null +++ b/LibreOJ/2055/data/sort6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f79a8faa6cc5af9f7f10f5271e08c9a138b8313918a0316d7e6af6a6988b7c4a +size 5 diff --git a/LibreOJ/2055/data/sort7.in b/LibreOJ/2055/data/sort7.in new file mode 100644 index 00000000..e393635a --- /dev/null +++ b/LibreOJ/2055/data/sort7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:789df9c17a590eeed830f23e368dc3db07ea59bf1c36f09bff295e3c720a606c +size 318911 diff --git a/LibreOJ/2055/data/sort7.out b/LibreOJ/2055/data/sort7.out new file mode 100644 index 00000000..274694f3 --- /dev/null +++ b/LibreOJ/2055/data/sort7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:309df7146066039424ec4267e9301dec379e48551a52fcb85118fb0e2fd3f098 +size 4 diff --git a/LibreOJ/2055/data/sort8.in b/LibreOJ/2055/data/sort8.in new file mode 100644 index 00000000..a61093ee --- /dev/null +++ b/LibreOJ/2055/data/sort8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f0ff140d3d2cdc5bb4a73ea30dbdb5751dda1f91c9f5a9fb4dd9d419e19091d +size 211334 diff --git a/LibreOJ/2055/data/sort8.out b/LibreOJ/2055/data/sort8.out new file mode 100644 index 00000000..9355cafe --- /dev/null +++ b/LibreOJ/2055/data/sort8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea0d1986cb5667ff4c66ac3a893de528460a6550ac72745d63ec5d7924a030e3 +size 4 diff --git a/LibreOJ/2055/data/sort9.in b/LibreOJ/2055/data/sort9.in new file mode 100644 index 00000000..ce68e1b7 --- /dev/null +++ b/LibreOJ/2055/data/sort9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6389cf1381b283aad2b3ee399506366d4ccd590035b084c4f1bb68c5fdbcf0e9 +size 2021736 diff --git a/LibreOJ/2055/data/sort9.out b/LibreOJ/2055/data/sort9.out new file mode 100644 index 00000000..dc6ea382 --- /dev/null +++ b/LibreOJ/2055/data/sort9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c07fb5465bf7a4fd2ce207be198e9da7786c614a2f096fd991e9d9552d6eb957 +size 6