diff --git a/LibreOJ/6279/6279.cpp b/LibreOJ/6279/6279.cpp new file mode 100644 index 00000000..4a654bac --- /dev/null +++ b/LibreOJ/6279/6279.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, c, t, a[N], b[N], st[N], ed[N], pos[N], add[N]; + +inline void process(int x) { + for (int i = st[x]; i <= ed[x]; i++) b[i] = a[i]; + std::sort(b + st[x], b + ed[x] + 1); +} + +void change(int l, int r, int c) { + int p = pos[l], + q = pos[r]; + + if (p == q) { + for (int i = l; i <= r; i++) a[i] += c; + process(p); + + return; + } + + for (int i = l; i <= ed[p]; i++) a[i] += c; + process(p); + for (int i = st[q]; i <= r; i++) a[i] += c; + process(q); + for (int i = p + 1; i <= q - 1; i++) add[i] += c; +} + +int query(int l, int r, int c) { + int p = pos[l], + q = pos[r]; + int res = std::numeric_limits::min(); + + if (p == q) { + for (int i = l; i <= r; i++) { + if (a[i] + add[p] < c) res = std::max(res, a[i] + add[p]); + } + } else { + for (int i = l; i <= ed[p]; i++) { + if (a[i] + add[p] < c) res = std::max(res, a[i] + add[p]); + } + for (int i = st[q]; i <= r; i++) { + if (a[i] + add[q] < c) res = std::max(res, a[i] + add[q]); + } + + for (int i = p + 1; i <= q - 1; i++) { + int _ = std::lower_bound(b + st[i], b + ed[i] + 1, c - add[i]) - b - 1; + + if (st[i] <= _ && _ <= ed[i]) res = std::max(res, b[_] + add[i]); + } + } + + return res == std::numeric_limits::min() ? -1 : res; +} + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + b[i] = a[i]; + } + + t = std::sqrt(n); + + for (c = 1;; c++) { + st[c] = (c - 1) * t + 1; + ed[c] = std::min(n, c * t); + if (c * t >= n) break; + } + + for (int i = 1; i <= c; i++) { + for (int j = st[i]; j <= ed[i]; j++) { + pos[j] = i; + } + std::sort(b + st[i], b + ed[i] + 1); + } + + for (int i = 1, op, l, r, c; i <= n; i++) { + cin >> op >> l >> r >> c; + + if (op == 0) { + change(l, r, c); + } else { // op == 1 + cout << query(l, r, c) << endl; + } + } + + return 0; +} diff --git a/LibreOJ/6279/data/a1.in b/LibreOJ/6279/data/a1.in new file mode 100644 index 00000000..9a0dce5b --- /dev/null +++ b/LibreOJ/6279/data/a1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0c49765353d4e19a0811ff3a8c16454e07a74ca45fddf02dc629419867b5ab2 +size 106630 diff --git a/LibreOJ/6279/data/a1.out b/LibreOJ/6279/data/a1.out new file mode 100644 index 00000000..32dd8fbd --- /dev/null +++ b/LibreOJ/6279/data/a1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a520ffede11c6a8e85c0e60e2abb38ae203808c246d6ac26ea055f239eae2d7c +size 7462 diff --git a/LibreOJ/6279/data/a10.in b/LibreOJ/6279/data/a10.in new file mode 100644 index 00000000..4b96457f --- /dev/null +++ b/LibreOJ/6279/data/a10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a988ddbdeeb4c5d11b9fb5ce01352134a131171ac51885ae116b591110c8969a +size 2355716 diff --git a/LibreOJ/6279/data/a10.out b/LibreOJ/6279/data/a10.out new file mode 100644 index 00000000..d619c170 --- /dev/null +++ b/LibreOJ/6279/data/a10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d50908044cda98ed57df6ee2032f74434fb00f6782f3c94ed1953549a0d28bda +size 488900 diff --git a/LibreOJ/6279/data/a2.in b/LibreOJ/6279/data/a2.in new file mode 100644 index 00000000..9a0dce5b --- /dev/null +++ b/LibreOJ/6279/data/a2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0c49765353d4e19a0811ff3a8c16454e07a74ca45fddf02dc629419867b5ab2 +size 106630 diff --git a/LibreOJ/6279/data/a2.out b/LibreOJ/6279/data/a2.out new file mode 100644 index 00000000..32dd8fbd --- /dev/null +++ b/LibreOJ/6279/data/a2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a520ffede11c6a8e85c0e60e2abb38ae203808c246d6ac26ea055f239eae2d7c +size 7462 diff --git a/LibreOJ/6279/data/a3.in b/LibreOJ/6279/data/a3.in new file mode 100644 index 00000000..8f7a6467 --- /dev/null +++ b/LibreOJ/6279/data/a3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62140209d48c68471d8adb0d7c9afd64d7c43899bbe26e1bd86084e510750a52 +size 106787 diff --git a/LibreOJ/6279/data/a3.out b/LibreOJ/6279/data/a3.out new file mode 100644 index 00000000..79338a3b --- /dev/null +++ b/LibreOJ/6279/data/a3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da25e540ebe6ed9334a5ae252001749c54b145bb525647ff5c92a02272b0ee8f +size 7608 diff --git a/LibreOJ/6279/data/a4.in b/LibreOJ/6279/data/a4.in new file mode 100644 index 00000000..fe1b2995 --- /dev/null +++ b/LibreOJ/6279/data/a4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f61193ef5cb925faf4caa5ea7e9d5da4c0a0948705187cf178622b8cc22660d8 +size 2355690 diff --git a/LibreOJ/6279/data/a4.out b/LibreOJ/6279/data/a4.out new file mode 100644 index 00000000..1ac62e18 --- /dev/null +++ b/LibreOJ/6279/data/a4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:961ff42be361b2d261dd3e60b9f1661216320c48e5aa596d5d9821f5650fe865 +size 488993 diff --git a/LibreOJ/6279/data/a5.in b/LibreOJ/6279/data/a5.in new file mode 100644 index 00000000..7b503c10 --- /dev/null +++ b/LibreOJ/6279/data/a5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:020b16ff689fbefd664d8fe3f1e97fc270f9755aff86e47265a156bb7abe6dda +size 2355480 diff --git a/LibreOJ/6279/data/a5.out b/LibreOJ/6279/data/a5.out new file mode 100644 index 00000000..82329a0a --- /dev/null +++ b/LibreOJ/6279/data/a5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f2bd61b16e397e7a21debd694f0e875659d838026742f45dbd063175e89b619 +size 488851 diff --git a/LibreOJ/6279/data/a6.in b/LibreOJ/6279/data/a6.in new file mode 100644 index 00000000..b435964f --- /dev/null +++ b/LibreOJ/6279/data/a6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed4a08e52b87cd3dac09d8f9d96353e38d88bf57b68574d66453098bde6f48b5 +size 2355574 diff --git a/LibreOJ/6279/data/a6.out b/LibreOJ/6279/data/a6.out new file mode 100644 index 00000000..3da90c73 --- /dev/null +++ b/LibreOJ/6279/data/a6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e87e4e4cbe83e4d3d39823946a2b5abaf8ed25abf8db51640daaa5a591c3fd2 +size 488588 diff --git a/LibreOJ/6279/data/a7.in b/LibreOJ/6279/data/a7.in new file mode 100644 index 00000000..b12f26b1 --- /dev/null +++ b/LibreOJ/6279/data/a7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08e577dd7d2c5bfec289a21f696336160e90773f8ce6a194ca100fbb17dbfa64 +size 2355357 diff --git a/LibreOJ/6279/data/a7.out b/LibreOJ/6279/data/a7.out new file mode 100644 index 00000000..140fc93e --- /dev/null +++ b/LibreOJ/6279/data/a7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:598b183e45d0be17acdbbab32034e2aacd980cbd9cc0b9752aa4e8a8cc398565 +size 488890 diff --git a/LibreOJ/6279/data/a8.in b/LibreOJ/6279/data/a8.in new file mode 100644 index 00000000..f508654d --- /dev/null +++ b/LibreOJ/6279/data/a8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cc3fe3dcf5cfc5b03a1d12c6beb7c5c5d1ca67084d8f909898df00dbcf90e9a1 +size 2355462 diff --git a/LibreOJ/6279/data/a8.out b/LibreOJ/6279/data/a8.out new file mode 100644 index 00000000..376d5f6d --- /dev/null +++ b/LibreOJ/6279/data/a8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:933abe424a066dacc8fdadcef19d7adbedcf73c3f14921617b35bdbf0281680e +size 488910 diff --git a/LibreOJ/6279/data/a9.in b/LibreOJ/6279/data/a9.in new file mode 100644 index 00000000..a9c72b5c --- /dev/null +++ b/LibreOJ/6279/data/a9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e883576fdaf8a63946ef4a00723a44cf7cbf3b0397e3203d3c34441c890a778 +size 2355832 diff --git a/LibreOJ/6279/data/a9.out b/LibreOJ/6279/data/a9.out new file mode 100644 index 00000000..76cc1eef --- /dev/null +++ b/LibreOJ/6279/data/a9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92e6e1bf85e383dbff4ded01796c4864f8f5bde3407cb0b6acddcc09bec3fb31 +size 488951