diff --git a/LibreOJ/6278/6278.cpp b/LibreOJ/6278/6278.cpp new file mode 100644 index 00000000..f412cf8f --- /dev/null +++ b/LibreOJ/6278/6278.cpp @@ -0,0 +1,103 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e5 + 5; + +int n, t, c; +long long a[N], b[N], st[N], ed[N], pos[N], add[N]; + +void change(int l, int r, int k) { + int p = pos[l], + q = pos[r]; + + if (p == q) { + for (int i = l; i <= r; i++) a[i] += k; + + for (int i = st[p]; i <= ed[p]; i++) b[i] = a[i]; + + std::sort(b + st[p], b + ed[p] + 1); + + return; + } + + for (int i = p + 1; i <= q - 1; i++) add[i] += k; + + for (int i = l; i <= ed[p]; i++) a[i] += k; + for (int i = st[p]; i <= ed[p]; i++) b[i] = a[i]; + std::sort(b + st[p], b + ed[p] + 1); + + for (int i = st[q]; i <= r; i++) a[i] += k; + for (int i = st[q]; i <= ed[q]; i++) b[i] = a[i]; + std::sort(b + st[q], b + ed[q] + 1); +} + +int query(int l, int r, long long k) { + int p = pos[l], + q = pos[r]; + int cnt = 0; + + if (p == q) { + for (int i = l; i <= r; i++) { + if (a[i] + add[p] < k) cnt++; + } + + return cnt; + } + + for (int i = p + 1; i <= q - 1; i++) { + cnt += std::upper_bound(b + st[i], b + ed[i] + 1, k - add[i] - 1) - b - st[i]; + } + + for (int i = l; i <= ed[p]; i++) { + if (a[i] + add[p] < k) cnt++; + } + for (int i = st[q]; i <= r; i++) { + if (a[i] + add[q] < k) cnt++; + } + + return cnt; +} + +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, 1ll * c * c) << endl; + } + } + + return 0; +} diff --git a/LibreOJ/6278/data/a1.in b/LibreOJ/6278/data/a1.in new file mode 100644 index 00000000..9a0dce5b --- /dev/null +++ b/LibreOJ/6278/data/a1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0c49765353d4e19a0811ff3a8c16454e07a74ca45fddf02dc629419867b5ab2 +size 106630 diff --git a/LibreOJ/6278/data/a1.out b/LibreOJ/6278/data/a1.out new file mode 100644 index 00000000..2dc5d323 --- /dev/null +++ b/LibreOJ/6278/data/a1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d6e3f832fef67ea46d001ed7a3bf4f5b1094479cb7518d60854b54076fb446c8 +size 10559 diff --git a/LibreOJ/6278/data/a10.in b/LibreOJ/6278/data/a10.in new file mode 100644 index 00000000..126dfc44 --- /dev/null +++ b/LibreOJ/6278/data/a10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d4b0743528b6b2b6dec1924877fea00f4d5bbde3ce4f0143a831878a24eefc1 +size 1166327 diff --git a/LibreOJ/6278/data/a10.out b/LibreOJ/6278/data/a10.out new file mode 100644 index 00000000..4a4891d2 --- /dev/null +++ b/LibreOJ/6278/data/a10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c88273fd00dd89cbb33c3b23c81a0ac8ad754d245df091118152d757b9d47696 +size 105863 diff --git a/LibreOJ/6278/data/a2.in b/LibreOJ/6278/data/a2.in new file mode 100644 index 00000000..9a0dce5b --- /dev/null +++ b/LibreOJ/6278/data/a2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0c49765353d4e19a0811ff3a8c16454e07a74ca45fddf02dc629419867b5ab2 +size 106630 diff --git a/LibreOJ/6278/data/a2.out b/LibreOJ/6278/data/a2.out new file mode 100644 index 00000000..2dc5d323 --- /dev/null +++ b/LibreOJ/6278/data/a2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d6e3f832fef67ea46d001ed7a3bf4f5b1094479cb7518d60854b54076fb446c8 +size 10559 diff --git a/LibreOJ/6278/data/a3.in b/LibreOJ/6278/data/a3.in new file mode 100644 index 00000000..8f7a6467 --- /dev/null +++ b/LibreOJ/6278/data/a3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62140209d48c68471d8adb0d7c9afd64d7c43899bbe26e1bd86084e510750a52 +size 106787 diff --git a/LibreOJ/6278/data/a3.out b/LibreOJ/6278/data/a3.out new file mode 100644 index 00000000..521a791c --- /dev/null +++ b/LibreOJ/6278/data/a3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1fb511b2b457117cf4830b17f59e60f3f5124c4308bcfe190b118e3f22fa005c +size 10750 diff --git a/LibreOJ/6278/data/a4.in b/LibreOJ/6278/data/a4.in new file mode 100644 index 00000000..67701cf7 --- /dev/null +++ b/LibreOJ/6278/data/a4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e36644e2a5c7e0107564826a55d82e38d8054685a4f441be584010c2f5da30e2 +size 1166550 diff --git a/LibreOJ/6278/data/a4.out b/LibreOJ/6278/data/a4.out new file mode 100644 index 00000000..1f207247 --- /dev/null +++ b/LibreOJ/6278/data/a4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a30c74401a8f54e8c8f19049bd4f013e798b9af9d22f6e11c09739d17bf1d9e +size 104670 diff --git a/LibreOJ/6278/data/a5.in b/LibreOJ/6278/data/a5.in new file mode 100644 index 00000000..0069aba1 --- /dev/null +++ b/LibreOJ/6278/data/a5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a30a5d249b651e5d31de93c67d0422967fd03bac62a8fbfe0c7146da107b5e7 +size 1166917 diff --git a/LibreOJ/6278/data/a5.out b/LibreOJ/6278/data/a5.out new file mode 100644 index 00000000..f999c57c --- /dev/null +++ b/LibreOJ/6278/data/a5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:644e3070d9d3aec76ced600fbc48a77a1ea5967c1353799693a5dfb02fec3565 +size 106936 diff --git a/LibreOJ/6278/data/a6.in b/LibreOJ/6278/data/a6.in new file mode 100644 index 00000000..55b47108 --- /dev/null +++ b/LibreOJ/6278/data/a6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4422d8e0339f0cca21229d696a0cff59a9782a601d860b3e9e7ac95bdec58755 +size 1166429 diff --git a/LibreOJ/6278/data/a6.out b/LibreOJ/6278/data/a6.out new file mode 100644 index 00000000..18272e11 --- /dev/null +++ b/LibreOJ/6278/data/a6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2db4fbd5327dee1ed9ed1349efe8408cddb8c87359fd5af1c3515e3ec8ea3afd +size 104244 diff --git a/LibreOJ/6278/data/a7.in b/LibreOJ/6278/data/a7.in new file mode 100644 index 00000000..4fc7c7eb --- /dev/null +++ b/LibreOJ/6278/data/a7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f984f228613850789ef45667790a47414a1e880e2ebd1069075827fd7ebf5498 +size 1166901 diff --git a/LibreOJ/6278/data/a7.out b/LibreOJ/6278/data/a7.out new file mode 100644 index 00000000..6abd79b5 --- /dev/null +++ b/LibreOJ/6278/data/a7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b4e3c81fe358dabf908a209e8034b4dce75fda603086837665801403b5cae8fe +size 106420 diff --git a/LibreOJ/6278/data/a8.in b/LibreOJ/6278/data/a8.in new file mode 100644 index 00000000..0df52a63 --- /dev/null +++ b/LibreOJ/6278/data/a8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b43d31460b3fea56ed75fc6522ca4f6cb8da028c64f341a7a2611e7254cf941 +size 1166676 diff --git a/LibreOJ/6278/data/a8.out b/LibreOJ/6278/data/a8.out new file mode 100644 index 00000000..8d38597d --- /dev/null +++ b/LibreOJ/6278/data/a8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6533d1d143c5ccff8e55944c05eb1e5ca73472e186469895c12f945a59ecc2d8 +size 105679 diff --git a/LibreOJ/6278/data/a9.in b/LibreOJ/6278/data/a9.in new file mode 100644 index 00000000..f449b467 --- /dev/null +++ b/LibreOJ/6278/data/a9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:684d2f8509b4b1545531d1987e07255cc80a92cd12c6fff0eb0091dc152bbf65 +size 1166871 diff --git a/LibreOJ/6278/data/a9.out b/LibreOJ/6278/data/a9.out new file mode 100644 index 00000000..9f6c949a --- /dev/null +++ b/LibreOJ/6278/data/a9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd4caabd6bb41d7f6f5018fdaf262971e66304f6a154346561b13ca042212ec8 +size 105153