From 6ba659f32fe313e0a10051a2731271219a87f668 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 18 May 2022 20:20:16 +0800 Subject: [PATCH] =?UTF-8?q?#6281.=20=E6=95=B0=E5=88=97=E5=88=86=E5=9D=97?= =?UTF-8?q?=E5=85=A5=E9=97=A8=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1466003 --- LibreOJ/6281/6281.cpp | 124 ++++++++++++++++++++++++++++++++++++++ LibreOJ/6281/data/a1.in | 3 + LibreOJ/6281/data/a1.out | 3 + LibreOJ/6281/data/a10.in | 3 + LibreOJ/6281/data/a10.out | 3 + LibreOJ/6281/data/a2.in | 3 + LibreOJ/6281/data/a2.out | 3 + LibreOJ/6281/data/a3.in | 3 + LibreOJ/6281/data/a3.out | 3 + LibreOJ/6281/data/a4.in | 3 + LibreOJ/6281/data/a4.out | 3 + LibreOJ/6281/data/a5.in | 3 + LibreOJ/6281/data/a5.out | 3 + LibreOJ/6281/data/a6.in | 3 + LibreOJ/6281/data/a6.out | 3 + LibreOJ/6281/data/a7.in | 3 + LibreOJ/6281/data/a7.out | 3 + LibreOJ/6281/data/a8.in | 3 + LibreOJ/6281/data/a8.out | 3 + LibreOJ/6281/data/a9.in | 3 + LibreOJ/6281/data/a9.out | 3 + 21 files changed, 184 insertions(+) create mode 100644 LibreOJ/6281/6281.cpp create mode 100644 LibreOJ/6281/data/a1.in create mode 100644 LibreOJ/6281/data/a1.out create mode 100644 LibreOJ/6281/data/a10.in create mode 100644 LibreOJ/6281/data/a10.out create mode 100644 LibreOJ/6281/data/a2.in create mode 100644 LibreOJ/6281/data/a2.out create mode 100644 LibreOJ/6281/data/a3.in create mode 100644 LibreOJ/6281/data/a3.out create mode 100644 LibreOJ/6281/data/a4.in create mode 100644 LibreOJ/6281/data/a4.out create mode 100644 LibreOJ/6281/data/a5.in create mode 100644 LibreOJ/6281/data/a5.out create mode 100644 LibreOJ/6281/data/a6.in create mode 100644 LibreOJ/6281/data/a6.out create mode 100644 LibreOJ/6281/data/a7.in create mode 100644 LibreOJ/6281/data/a7.out create mode 100644 LibreOJ/6281/data/a8.in create mode 100644 LibreOJ/6281/data/a8.out create mode 100644 LibreOJ/6281/data/a9.in create mode 100644 LibreOJ/6281/data/a9.out diff --git a/LibreOJ/6281/6281.cpp b/LibreOJ/6281/6281.cpp new file mode 100644 index 00000000..68c90551 --- /dev/null +++ b/LibreOJ/6281/6281.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 50005; + +int n, t, c, a[N], st[N], ed[N], pos[N], sum[N]; +bool done[N]; + +void change(int l, int r) { + int p = pos[l], + q = pos[r]; + + if (p == q) { + for (int i = l; i <= r; i++) { + sum[p] -= a[i]; + a[i] = std::sqrt(a[i]); + sum[p] += a[i]; + } + + return; + } + + for (int i = l; i <= ed[p]; i++) { + sum[p] -= a[i]; + a[i] = std::floor(std::sqrt(a[i])); + sum[p] += a[i]; + } + + for (int i = st[q]; i <= r; i++) { + sum[q] -= a[i]; + a[i] = std::floor(std::sqrt(a[i])); + sum[q] += a[i]; + } + + for (int i = p + 1; i <= q - 1; i++) { + if (done[i]) continue; + + bool flag = true; + + for (int j = st[i]; j <= ed[i]; j++) { + sum[i] -= a[j]; + flag &= (a[j] = std::floor(std::sqrt(a[j]))) == 1; + sum[i] += a[j]; + } + + if (flag) done[i] = true; + } +} + +int query(int l, int r) { + int p = pos[l], + q = pos[r]; + int res = 0; + + if (p == q) { + if (done[p]) return r - l + 1; + + for (int i = l; i <= r; i++) { + res += a[i]; + } + + return res; + } + + for (int i = l; i <= ed[p]; i++) { + res += a[i]; + } + for (int i = st[q]; i <= r; i++) { + res += a[i]; + } + + for (int i = p + 1; i <= q - 1; i++) { + if (done[i]) { + res += ed[i] - st[i] + 1; + } else { + for (int j = st[i]; j <= ed[i]; j++) { + res += a[j]; + } + } + } + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> 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; + } + } + + for (int i = 1, op, l, r, c; i <= n; i++) { + cin >> op >> l >> r >> c; + + if (op == 0) { + change(l, r); + } else { // op == 1 + cout << query(l, r) << endl; + } + } + + return 0; +} diff --git a/LibreOJ/6281/data/a1.in b/LibreOJ/6281/data/a1.in new file mode 100644 index 00000000..9a0dce5b --- /dev/null +++ b/LibreOJ/6281/data/a1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0c49765353d4e19a0811ff3a8c16454e07a74ca45fddf02dc629419867b5ab2 +size 106630 diff --git a/LibreOJ/6281/data/a1.out b/LibreOJ/6281/data/a1.out new file mode 100644 index 00000000..faaee966 --- /dev/null +++ b/LibreOJ/6281/data/a1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70b3a8f5dd35246269c6b48e0ae2852f808328fcec636285e2ddf7502fe57bed +size 11406 diff --git a/LibreOJ/6281/data/a10.in b/LibreOJ/6281/data/a10.in new file mode 100644 index 00000000..126dfc44 --- /dev/null +++ b/LibreOJ/6281/data/a10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d4b0743528b6b2b6dec1924877fea00f4d5bbde3ce4f0143a831878a24eefc1 +size 1166327 diff --git a/LibreOJ/6281/data/a10.out b/LibreOJ/6281/data/a10.out new file mode 100644 index 00000000..f0b56b36 --- /dev/null +++ b/LibreOJ/6281/data/a10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8cc9f4220ee523db6202256a26da27f93f36de4c7c47da3543d238d7229862dd +size 140380 diff --git a/LibreOJ/6281/data/a2.in b/LibreOJ/6281/data/a2.in new file mode 100644 index 00000000..9a0dce5b --- /dev/null +++ b/LibreOJ/6281/data/a2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0c49765353d4e19a0811ff3a8c16454e07a74ca45fddf02dc629419867b5ab2 +size 106630 diff --git a/LibreOJ/6281/data/a2.out b/LibreOJ/6281/data/a2.out new file mode 100644 index 00000000..faaee966 --- /dev/null +++ b/LibreOJ/6281/data/a2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70b3a8f5dd35246269c6b48e0ae2852f808328fcec636285e2ddf7502fe57bed +size 11406 diff --git a/LibreOJ/6281/data/a3.in b/LibreOJ/6281/data/a3.in new file mode 100644 index 00000000..8f7a6467 --- /dev/null +++ b/LibreOJ/6281/data/a3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62140209d48c68471d8adb0d7c9afd64d7c43899bbe26e1bd86084e510750a52 +size 106787 diff --git a/LibreOJ/6281/data/a3.out b/LibreOJ/6281/data/a3.out new file mode 100644 index 00000000..bd9afba0 --- /dev/null +++ b/LibreOJ/6281/data/a3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d569eb86d0b4f53ae1956b7b2b2c12e057d8d1a8572e7818c4d8cc798b1f5085 +size 11662 diff --git a/LibreOJ/6281/data/a4.in b/LibreOJ/6281/data/a4.in new file mode 100644 index 00000000..67701cf7 --- /dev/null +++ b/LibreOJ/6281/data/a4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e36644e2a5c7e0107564826a55d82e38d8054685a4f441be584010c2f5da30e2 +size 1166550 diff --git a/LibreOJ/6281/data/a4.out b/LibreOJ/6281/data/a4.out new file mode 100644 index 00000000..3fa39442 --- /dev/null +++ b/LibreOJ/6281/data/a4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea0656ad3895703a5c4f332d1922b0e14a0c582b1ad868d2320a0a4dccba2847 +size 139550 diff --git a/LibreOJ/6281/data/a5.in b/LibreOJ/6281/data/a5.in new file mode 100644 index 00000000..0069aba1 --- /dev/null +++ b/LibreOJ/6281/data/a5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a30a5d249b651e5d31de93c67d0422967fd03bac62a8fbfe0c7146da107b5e7 +size 1166917 diff --git a/LibreOJ/6281/data/a5.out b/LibreOJ/6281/data/a5.out new file mode 100644 index 00000000..ba4e68ea --- /dev/null +++ b/LibreOJ/6281/data/a5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea71e302344c863142950343df7aa30ee03b4a684808fe9b3dcb17eca8809bc1 +size 141050 diff --git a/LibreOJ/6281/data/a6.in b/LibreOJ/6281/data/a6.in new file mode 100644 index 00000000..55b47108 --- /dev/null +++ b/LibreOJ/6281/data/a6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4422d8e0339f0cca21229d696a0cff59a9782a601d860b3e9e7ac95bdec58755 +size 1166429 diff --git a/LibreOJ/6281/data/a6.out b/LibreOJ/6281/data/a6.out new file mode 100644 index 00000000..4cc89691 --- /dev/null +++ b/LibreOJ/6281/data/a6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a52f18389feca8b25faa320891f2af3943f7c29b97da76e4887bd5a4bac32d46 +size 138588 diff --git a/LibreOJ/6281/data/a7.in b/LibreOJ/6281/data/a7.in new file mode 100644 index 00000000..4fc7c7eb --- /dev/null +++ b/LibreOJ/6281/data/a7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f984f228613850789ef45667790a47414a1e880e2ebd1069075827fd7ebf5498 +size 1166901 diff --git a/LibreOJ/6281/data/a7.out b/LibreOJ/6281/data/a7.out new file mode 100644 index 00000000..13e48934 --- /dev/null +++ b/LibreOJ/6281/data/a7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7494fa255d42dc43b3fe376cde3fbe5aa9ed795dc5cf6d4881b55260f1684b4 +size 140361 diff --git a/LibreOJ/6281/data/a8.in b/LibreOJ/6281/data/a8.in new file mode 100644 index 00000000..0df52a63 --- /dev/null +++ b/LibreOJ/6281/data/a8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b43d31460b3fea56ed75fc6522ca4f6cb8da028c64f341a7a2611e7254cf941 +size 1166676 diff --git a/LibreOJ/6281/data/a8.out b/LibreOJ/6281/data/a8.out new file mode 100644 index 00000000..45261251 --- /dev/null +++ b/LibreOJ/6281/data/a8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:312fe6e727e99ad06b89392d06bd868e64200fe9a2fd99084c9e64d448bd744e +size 139647 diff --git a/LibreOJ/6281/data/a9.in b/LibreOJ/6281/data/a9.in new file mode 100644 index 00000000..f449b467 --- /dev/null +++ b/LibreOJ/6281/data/a9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:684d2f8509b4b1545531d1987e07255cc80a92cd12c6fff0eb0091dc152bbf65 +size 1166871 diff --git a/LibreOJ/6281/data/a9.out b/LibreOJ/6281/data/a9.out new file mode 100644 index 00000000..4baf7dd2 --- /dev/null +++ b/LibreOJ/6281/data/a9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91f9465bd601d9048b6744b79fe4b801f61d1382c926aa6ede06db66f9f4666a +size 139251