diff --git a/AcWing/2488/2488.cpp b/AcWing/2488/2488.cpp new file mode 100644 index 00000000..26d7a2f0 --- /dev/null +++ b/AcWing/2488/2488.cpp @@ -0,0 +1,101 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e4 + 5; + +int n, m, a[N]; + +struct node : public std::multiset { + int l, r; + + node() + : l(0), r(0) {} + + node(int _l, int _r) + : l(_l), r(_r) { + insert(std::numeric_limits::min()); + insert(std::numeric_limits::max()); + } +} tr[N << 2]; + +void build(int u, int l, int r) { + tr[u] = node(l, r); + + for (int i = l; i <= r; i++) { + tr[u].insert(a[i]); + } + + if (l == r) return; + + int mid = l + r >> 1; + + build(u << 1, l, mid); + build(u << 1 | 1, mid + 1, r); +} + +void modify(int u, int p, int x) { + tr[u].erase(tr[u].find(a[p])); + tr[u].insert(x); + + if (tr[u].l == tr[u].r) return; + + int mid = tr[u].l + tr[u].r >> 1; + + if (p <= mid) modify(u << 1, p, x); + else modify(u << 1 | 1, p, x); +} + +int query(int u, int l, int r, int x) { + if (l <= tr[u].l && tr[u].r <= r) { + return *--tr[u].lower_bound(x); + } + + int mid = tr[u].l + tr[u].r >> 1; + int res = std::numeric_limits::min(); + + if (l <= mid) res = std::max(res, query(u << 1, l, r, x)); + if (r > mid) res = std::max(res, query(u << 1 | 1, l, r, x)); + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + build(1, 1, n); + + while (m--) { + int op; + + cin >> op; + + if (op == 1) { + int p, x; + + cin >> p >> x; + + modify(1, p, x); + a[p] = x; + } else { // op == 2 + int l, r, x; + + cin >> l >> r >> x; + + cout << query(1, l, r, x) << endl; + } + } + + return 0; +} diff --git a/AcWing/2488/data/2.ans b/AcWing/2488/data/2.ans new file mode 100644 index 00000000..fa0d9013 --- /dev/null +++ b/AcWing/2488/data/2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae87e3ad8ba15b5ad7dcd6311a4bf8f387a4a701851df786be9ce7ef6012c2af +size 46 diff --git a/AcWing/2488/data/2.in b/AcWing/2488/data/2.in new file mode 100644 index 00000000..33e30b0e --- /dev/null +++ b/AcWing/2488/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:704350bc5aa4e0b11337f2789b36a171af5282897eca5c4c47b956a2dfd2d9f9 +size 322