From 508ed89e83872818ec0f1224408dd22bd6d738da Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 22 Dec 2022 21:26:36 +0800 Subject: [PATCH] =?UTF-8?q?4821.=20[Sdoi2017]=E7=9B=B8=E5=85=B3=E5=88=86?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/63a45a58b053be17396a0036 --- BZOJ/4821/4821.cpp | 202 +++++++++++++++++++++++++++++++++++++ BZOJ/4821/data/1.in | 3 + BZOJ/4821/data/1.out | 3 + BZOJ/4821/data/10.in | 3 + BZOJ/4821/data/10.out | 3 + BZOJ/4821/data/11.in | 3 + BZOJ/4821/data/11.out | 3 + BZOJ/4821/data/2.in | 3 + BZOJ/4821/data/2.out | 3 + BZOJ/4821/data/3.in | 3 + BZOJ/4821/data/3.out | 3 + BZOJ/4821/data/4.in | 3 + BZOJ/4821/data/4.out | 3 + BZOJ/4821/data/5.in | 3 + BZOJ/4821/data/5.out | 3 + BZOJ/4821/data/6.in | 3 + BZOJ/4821/data/6.out | 3 + BZOJ/4821/data/7.in | 3 + BZOJ/4821/data/7.out | 3 + BZOJ/4821/data/8.in | 3 + BZOJ/4821/data/8.out | 3 + BZOJ/4821/data/9.in | 3 + BZOJ/4821/data/9.out | 3 + BZOJ/4821/data/checker.cpp | 3 + 24 files changed, 271 insertions(+) create mode 100644 BZOJ/4821/4821.cpp create mode 100644 BZOJ/4821/data/1.in create mode 100644 BZOJ/4821/data/1.out create mode 100644 BZOJ/4821/data/10.in create mode 100644 BZOJ/4821/data/10.out create mode 100644 BZOJ/4821/data/11.in create mode 100644 BZOJ/4821/data/11.out create mode 100644 BZOJ/4821/data/2.in create mode 100644 BZOJ/4821/data/2.out create mode 100644 BZOJ/4821/data/3.in create mode 100644 BZOJ/4821/data/3.out create mode 100644 BZOJ/4821/data/4.in create mode 100644 BZOJ/4821/data/4.out create mode 100644 BZOJ/4821/data/5.in create mode 100644 BZOJ/4821/data/5.out create mode 100644 BZOJ/4821/data/6.in create mode 100644 BZOJ/4821/data/6.out create mode 100644 BZOJ/4821/data/7.in create mode 100644 BZOJ/4821/data/7.out create mode 100644 BZOJ/4821/data/8.in create mode 100644 BZOJ/4821/data/8.out create mode 100644 BZOJ/4821/data/9.in create mode 100644 BZOJ/4821/data/9.out create mode 100644 BZOJ/4821/data/checker.cpp diff --git a/BZOJ/4821/4821.cpp b/BZOJ/4821/4821.cpp new file mode 100644 index 00000000..e5ebd610 --- /dev/null +++ b/BZOJ/4821/4821.cpp @@ -0,0 +1,202 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +struct node { + int l, r; + __int128 sum_x, sum_y, sum_xx, sum_xy; + __int128 lazy_s, lazy_t; + bool covered; + + node(const int &_l = 0, const int &_r = 0) + : l(_l), + r(_r), + sum_x(0), + sum_y(0), + sum_xx(0), + sum_xy(0), + lazy_s(0), + lazy_t(0), + covered(false) {} + + node operator+(const node &rhs) const { + node res; + + res.l = l; + res.r = rhs.r; + res.sum_x = sum_x + rhs.sum_x; + res.sum_y = sum_y + rhs.sum_y; + res.sum_xx = sum_xx + rhs.sum_xx; + res.sum_xy = sum_xy + rhs.sum_xy; + + return res; + } +} tr[N << 2]; + +int n, m, x[N], y[N]; + +__int128 square_sum(__int128 x) { + return x * (x + 1) * (2 * x + 1) / 6; +} + +__int128 square_sum(__int128 l, __int128 r) { + return square_sum(r) - square_sum(l - 1); +} + +/// Add (s, t) to each element under tr[u] +void modify_node(int u, __int128 s, __int128 t) { + tr[u].lazy_s += s; + tr[u].lazy_t += t; + + tr[u].sum_xx += 2 * s * tr[u].sum_x + s * s * (tr[u].r - tr[u].l + 1); + tr[u].sum_xy += t * tr[u].sum_x + s * tr[u].sum_y + s * t * (tr[u].r - tr[u].l + 1); + + tr[u].sum_x += s * (tr[u].r - tr[u].l + 1); + tr[u].sum_y += t * (tr[u].r - tr[u].l + 1); +} + +/// x[i] = y[i] = i +void change_node(int u) { + tr[u].lazy_s = tr[u].lazy_t = 0; + tr[u].sum_x = tr[u].sum_y = static_cast<__int128>(tr[u].l + tr[u].r) * (tr[u].r - tr[u].l + 1) / 2; + tr[u].sum_xx = tr[u].sum_xy = square_sum(tr[u].l, tr[u].r); + tr[u].covered = true; +} + +void pushup(int u) { + tr[u] = tr[u << 1] + tr[u << 1 | 1]; +} + +void pushdown(int u) { + if (tr[u].covered) { + change_node(u << 1); + change_node(u << 1 | 1); + + tr[u].covered = false; + } + + modify_node(u << 1, tr[u].lazy_s, tr[u].lazy_t); + modify_node(u << 1 | 1, tr[u].lazy_s, tr[u].lazy_t); + + tr[u].lazy_s = tr[u].lazy_t = 0; +} + +void build(int u, int l, int r) { + tr[u] = node(l, r); + + if (l == r) { + tr[u].sum_x = x[l]; + tr[u].sum_y = y[l]; + tr[u].sum_xx = static_cast<__int128>(x[l]) * x[l]; + tr[u].sum_xy = static_cast<__int128>(x[l]) * y[l]; + + return; + } + + int mid = l + r >> 1; + + build(u << 1, l, mid); + build(u << 1 | 1, mid + 1, r); + + pushup(u); +} + +void modify(int u, int l, int r, __int128 s, __int128 t) { + if (l <= tr[u].l && tr[u].r <= r) { + modify_node(u, s, t); + + return; + } + + int mid = tr[u].l + tr[u].r >> 1; + + pushdown(u); + + if (l <= mid) modify(u << 1, l, r, s, t); + if (r > mid) modify(u << 1 | 1, l, r, s, t); + + pushup(u); +} + +void change(int u, int l, int r, __int128 s, __int128 t) { + if (l <= tr[u].l && tr[u].r <= r) { + change_node(u); + modify_node(u, s, t); + + return; + } + + int mid = tr[u].l + tr[u].r >> 1; + + pushdown(u); + + if (l <= mid) change(u << 1, l, r, s, t); + if (r > mid) change(u << 1 | 1, l, r, s, t); + + pushup(u); +} + +node query(int u, int l, int r) { + if (l <= tr[u].l && tr[u].r <= r) return tr[u]; + + int mid = tr[u].l + tr[u].r >> 1; + node res; + + pushdown(u); + + if (l <= mid) res = res + query(u << 1, l, r); + if (r > mid) res = res + query(u << 1 | 1, l, r); + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + cin >> x[i]; + } + + for (int i = 1; i <= n; i++) { + cin >> y[i]; + } + + build(1, 1, n); + + while (m--) { + int op, l, r; + + cin >> op >> l >> r; + + if (op == 1) { + auto res = query(1, l, r); + + double x = static_cast(res.sum_xy) - static_cast(res.sum_x) * res.sum_y / (r - l + 1), + y = static_cast(res.sum_xx) - static_cast(res.sum_x) * res.sum_x / (r - l + 1); + + cout << std::fixed << std::setprecision(10) << x / y << endl; + } else if (op == 2) { + int s, t; + + cin >> s >> t; + + modify(1, l, r, s, t); + } else { // op == 3 + int s, t; + + cin >> s >> t; + + change(1, l, r, s, t); + } + } + + return 0; +} diff --git a/BZOJ/4821/data/1.in b/BZOJ/4821/data/1.in new file mode 100644 index 00000000..d47a11aa --- /dev/null +++ b/BZOJ/4821/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:916bf6f1385b83d216997dbd3d96447dac504207c76272053ac6116a85684ed3 +size 21154 diff --git a/BZOJ/4821/data/1.out b/BZOJ/4821/data/1.out new file mode 100644 index 00000000..c337f441 --- /dev/null +++ b/BZOJ/4821/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:535aeb1b810481f76dc6a32fd8cbaa20964978f6b796559383178ea53c62d70f +size 2981 diff --git a/BZOJ/4821/data/10.in b/BZOJ/4821/data/10.in new file mode 100644 index 00000000..d03f3250 --- /dev/null +++ b/BZOJ/4821/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbb63980bf2afa8c6a66fe116f9ec0139c2832b5464d34e549f701e2131365eb +size 3031499 diff --git a/BZOJ/4821/data/10.out b/BZOJ/4821/data/10.out new file mode 100644 index 00000000..282fd074 --- /dev/null +++ b/BZOJ/4821/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3c8b1e8be3c5bb0e14b3df4ff8920acb096ecd2077e6e69eebe1caabd6d984c +size 606626 diff --git a/BZOJ/4821/data/11.in b/BZOJ/4821/data/11.in new file mode 100644 index 00000000..cff9e4f3 --- /dev/null +++ b/BZOJ/4821/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2731fca9ab240286e92bd347e24e21f087aace67c2d92cac9a733ef216ac843 +size 3025416 diff --git a/BZOJ/4821/data/11.out b/BZOJ/4821/data/11.out new file mode 100644 index 00000000..21516f42 --- /dev/null +++ b/BZOJ/4821/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:049465d1f9af8247f47e646f5b280eeb9d2052aea38e619bc07ee997d8b4f75a +size 630702 diff --git a/BZOJ/4821/data/2.in b/BZOJ/4821/data/2.in new file mode 100644 index 00000000..c18ece58 --- /dev/null +++ b/BZOJ/4821/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5878f825c03d078b506b1f2660a6f698ce805f13cccd3ec103a743c6bbdcf8f2 +size 3034684 diff --git a/BZOJ/4821/data/2.out b/BZOJ/4821/data/2.out new file mode 100644 index 00000000..6dd6249d --- /dev/null +++ b/BZOJ/4821/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cfced9546c8b80fc3abb07f69ae8415df98a3ca9cdbb0e3624445d575cc370e6 +size 654334 diff --git a/BZOJ/4821/data/3.in b/BZOJ/4821/data/3.in new file mode 100644 index 00000000..6d8afe78 --- /dev/null +++ b/BZOJ/4821/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:89ed3114e89debc04b227fea1a7b9e2ebfd43f4aac13220eec52cf4232561fd0 +size 28596 diff --git a/BZOJ/4821/data/3.out b/BZOJ/4821/data/3.out new file mode 100644 index 00000000..cbdee36c --- /dev/null +++ b/BZOJ/4821/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6209d64e068cfe888846a7aa63c15091c85fbea24651520c6941ccf89b143a81 +size 3903 diff --git a/BZOJ/4821/data/4.in b/BZOJ/4821/data/4.in new file mode 100644 index 00000000..d5314c05 --- /dev/null +++ b/BZOJ/4821/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:387a16a1bff09a7419a9cad271dbdbd340d5d1cc91a49f50fd96bee875a6a0fb +size 3380999 diff --git a/BZOJ/4821/data/4.out b/BZOJ/4821/data/4.out new file mode 100644 index 00000000..058f152e --- /dev/null +++ b/BZOJ/4821/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2938856493e79d158dea117583badfcbd150cdc5bd18e844ee7038e75d20052a +size 425093 diff --git a/BZOJ/4821/data/5.in b/BZOJ/4821/data/5.in new file mode 100644 index 00000000..e6c6e8b5 --- /dev/null +++ b/BZOJ/4821/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ba4bac3ca5a677e4eaffb0a911a23c1605f4be8401a656258ef54a06911d35e2 +size 55 diff --git a/BZOJ/4821/data/5.out b/BZOJ/4821/data/5.out new file mode 100644 index 00000000..f4e3502c --- /dev/null +++ b/BZOJ/4821/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8cd37504092213b1f2cee40ce7b96b47603a09343b1c8969bf314802b3b7e188 +size 41 diff --git a/BZOJ/4821/data/6.in b/BZOJ/4821/data/6.in new file mode 100644 index 00000000..bcba0353 --- /dev/null +++ b/BZOJ/4821/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87c6e0fb5b8c8157696a5f631c911e4dc34b43e1461d206f9e3ffaa1b1fd071a +size 2861388 diff --git a/BZOJ/4821/data/6.out b/BZOJ/4821/data/6.out new file mode 100644 index 00000000..3b569fed --- /dev/null +++ b/BZOJ/4821/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87891e80a6732296f6ffbbbd34986ed9d7d05d01cb52eaa8523734b6da34a96a +size 616979 diff --git a/BZOJ/4821/data/7.in b/BZOJ/4821/data/7.in new file mode 100644 index 00000000..99a9db51 --- /dev/null +++ b/BZOJ/4821/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfd97db6f8c3f36801951faff2ebb988ae96a3819995ec1f31e1b4faf19efe26 +size 3126753 diff --git a/BZOJ/4821/data/7.out b/BZOJ/4821/data/7.out new file mode 100644 index 00000000..656c6ee0 --- /dev/null +++ b/BZOJ/4821/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e954db9cfa13ba3787c3b54ef98ee47c3f3420aac22354faff6e738ce093523 +size 644467 diff --git a/BZOJ/4821/data/8.in b/BZOJ/4821/data/8.in new file mode 100644 index 00000000..857d7ab1 --- /dev/null +++ b/BZOJ/4821/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:630397f2e15cc3da2c029deae2a88b2efc4d781d104cf1af95c52fd5b269ade2 +size 3362995 diff --git a/BZOJ/4821/data/8.out b/BZOJ/4821/data/8.out new file mode 100644 index 00000000..0e41c7bc --- /dev/null +++ b/BZOJ/4821/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cec45c4675336d364c1aadd27afed612fa793534151faa950e5f26ffc011ea63 +size 428860 diff --git a/BZOJ/4821/data/9.in b/BZOJ/4821/data/9.in new file mode 100644 index 00000000..a6cc19b2 --- /dev/null +++ b/BZOJ/4821/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54c032914b11c6397c9507175aec3a4cfb827a044657a0436aa3685d1fcc5f5d +size 3298110 diff --git a/BZOJ/4821/data/9.out b/BZOJ/4821/data/9.out new file mode 100644 index 00000000..f09d8423 --- /dev/null +++ b/BZOJ/4821/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7838d3320b9ebc840b7236c2aa44479daf76ddefbbca20afa168818527c8dccc +size 406898 diff --git a/BZOJ/4821/data/checker.cpp b/BZOJ/4821/data/checker.cpp new file mode 100644 index 00000000..1f0cf047 --- /dev/null +++ b/BZOJ/4821/data/checker.cpp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:944ade9aa014b0608719469d96f8bdb4e66435be02a647dd2b83a691b558c97e +size 733