From a0e921f847015bf6298faf3b2d1f13f7e9427e60 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 28 Sep 2022 12:16:39 +0800 Subject: [PATCH] =?UTF-8?q?#895.=20=E3=80=8C=E9=9B=85=E7=A4=BC=E9=9B=86?= =?UTF-8?q?=E8=AE=AD=202018=20Day1=E3=80=8D=E5=85=BB=E8=8A=B1=EF=BC=88flow?= =?UTF-8?q?er=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/58169 --- S2OJ/895/895.cpp | 93 ++++++++++++++++++++++++++++++++++++++ S2OJ/895/data/data1.in | 3 ++ S2OJ/895/data/data1.out | 3 ++ S2OJ/895/data/data10.in | 3 ++ S2OJ/895/data/data10.out | 3 ++ S2OJ/895/data/data2.in | 3 ++ S2OJ/895/data/data2.out | 3 ++ S2OJ/895/data/data3.in | 3 ++ S2OJ/895/data/data3.out | 3 ++ S2OJ/895/data/data4.in | 3 ++ S2OJ/895/data/data4.out | 3 ++ S2OJ/895/data/data5.in | 3 ++ S2OJ/895/data/data5.out | 3 ++ S2OJ/895/data/data6.in | 3 ++ S2OJ/895/data/data6.out | 3 ++ S2OJ/895/data/data7.in | 3 ++ S2OJ/895/data/data7.out | 3 ++ S2OJ/895/data/data8.in | 3 ++ S2OJ/895/data/data8.out | 3 ++ S2OJ/895/data/data9.in | 3 ++ S2OJ/895/data/data9.out | 3 ++ S2OJ/895/data/problem.conf | 3 ++ 22 files changed, 156 insertions(+) create mode 100644 S2OJ/895/895.cpp create mode 100644 S2OJ/895/data/data1.in create mode 100644 S2OJ/895/data/data1.out create mode 100644 S2OJ/895/data/data10.in create mode 100644 S2OJ/895/data/data10.out create mode 100644 S2OJ/895/data/data2.in create mode 100644 S2OJ/895/data/data2.out create mode 100644 S2OJ/895/data/data3.in create mode 100644 S2OJ/895/data/data3.out create mode 100644 S2OJ/895/data/data4.in create mode 100644 S2OJ/895/data/data4.out create mode 100644 S2OJ/895/data/data5.in create mode 100644 S2OJ/895/data/data5.out create mode 100644 S2OJ/895/data/data6.in create mode 100644 S2OJ/895/data/data6.out create mode 100644 S2OJ/895/data/data7.in create mode 100644 S2OJ/895/data/data7.out create mode 100644 S2OJ/895/data/data8.in create mode 100644 S2OJ/895/data/data8.out create mode 100644 S2OJ/895/data/data9.in create mode 100644 S2OJ/895/data/data9.out create mode 100644 S2OJ/895/data/problem.conf diff --git a/S2OJ/895/895.cpp b/S2OJ/895/895.cpp new file mode 100644 index 00000000..e3fedafd --- /dev/null +++ b/S2OJ/895/895.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5, + M = 505; + +int n, m, a[N]; +std::tuple q[N]; +int b, t, st[M], ed[M], pos[N], max[M][N]; +int tmp[N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + for (b = 1, t = std::sqrt(n);; b++) { + st[b] = (b - 1) * t + 1; + ed[b] = std::min(n, b * t); + + if (b * t >= n) break; + } + + for (int i = 1; i <= b; i++) { + for (int j = st[i]; j <= ed[i]; j++) { + pos[j] = i; + } + } + + for (int i = 1; i <= m; i++) { + cin >> std::get<0>(q[i]) >> std::get<1>(q[i]) >> std::get<2>(q[i]); + } + + int max_k = std::get<2>(*std::max_element(q + 1, q + 1 + m, [&](auto a, auto b) -> bool { return std::get<2>(a) < std::get<2>(b); })); + + for (int i = 1; i <= b; i++) { + std::fill_n(tmp, N, 0); + + for (int j = st[i]; j <= ed[i]; j++) { + tmp[a[j]] = a[j]; + } + + for (int j = 1; j <= 100000; j++) { + tmp[j] = std::max(tmp[j], tmp[j - 1]); + } + + for (int j = 1; j <= max_k; j++) { + for (int k = 0; k <= max_k; k += j) { + max[i][j] = std::max(max[i][j], tmp[std::min(j + k - 1, 100000)] - k); + } + } + } + + for (int i = 1; i <= m; i++) { + int l, r, k, res = 0; + + std::tie(l, r, k) = q[i]; + + if (pos[l] == pos[r]) { + for (int j = l; j <= r; j++) { + res = std::max(res, a[j] % k); + } + } else { + for (int j = l; j <= ed[pos[l]]; j++) { + res = std::max(res, a[j] % k); + } + + for (int j = pos[l] + 1; j <= pos[r] - 1; j++) { + res = std::max(res, max[j][k]); + } + + for (int j = st[pos[r]]; j <= r; j++) { + res = std::max(res, a[j] % k); + } + } + + cout << res << endl; + } + + return 0; +} diff --git a/S2OJ/895/data/data1.in b/S2OJ/895/data/data1.in new file mode 100644 index 00000000..06060ac7 --- /dev/null +++ b/S2OJ/895/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1df6e7a8c9faafd85db3304ebe8491c4ca432fa0562a9c804a9a9f34fd549a6 +size 84200 diff --git a/S2OJ/895/data/data1.out b/S2OJ/895/data/data1.out new file mode 100644 index 00000000..d5356ed6 --- /dev/null +++ b/S2OJ/895/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d30bc6af9f6c762935996f61e845b6b7ece5257a927ef0947a54f5c94a4ff9b +size 26667 diff --git a/S2OJ/895/data/data10.in b/S2OJ/895/data/data10.in new file mode 100644 index 00000000..caeb2a1c --- /dev/null +++ b/S2OJ/895/data/data10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:563580a5c45f81c7823b65c28f5a61f068791625733cb286fa0007744bd51397 +size 2116781 diff --git a/S2OJ/895/data/data10.out b/S2OJ/895/data/data10.out new file mode 100644 index 00000000..75bc669d --- /dev/null +++ b/S2OJ/895/data/data10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:01b7c4490f95cbffc8f416baf480926d56c39917b1349812ee07200ed8f72656 +size 499651 diff --git a/S2OJ/895/data/data2.in b/S2OJ/895/data/data2.in new file mode 100644 index 00000000..2508f5cd --- /dev/null +++ b/S2OJ/895/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b24bf9074a0273bdd162238b4cdc6dfc5ad5c4be38f12956736ce7647a817a42 +size 2318721 diff --git a/S2OJ/895/data/data2.out b/S2OJ/895/data/data2.out new file mode 100644 index 00000000..206eca92 --- /dev/null +++ b/S2OJ/895/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b95b2e5797d84d0b5af3791987484d21448f460eeabbf58e606848020ee8c65 +size 665971 diff --git a/S2OJ/895/data/data3.in b/S2OJ/895/data/data3.in new file mode 100644 index 00000000..1ab80d92 --- /dev/null +++ b/S2OJ/895/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e5f149d06bc153bbe4051ce8ada2372dc1d2b48118b0e06a98d16d1053698e1 +size 2318574 diff --git a/S2OJ/895/data/data3.out b/S2OJ/895/data/data3.out new file mode 100644 index 00000000..63fbbe5b --- /dev/null +++ b/S2OJ/895/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3eed6b0817478c70ece18e782abe1d5cc6572cb0f14a370b91314e998a8e8b62 +size 666015 diff --git a/S2OJ/895/data/data4.in b/S2OJ/895/data/data4.in new file mode 100644 index 00000000..1edecf77 --- /dev/null +++ b/S2OJ/895/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:339228ce55d3a2d76328b506dd68c1548fb4849be8ea389fdb0c14dd4d301cca +size 84230 diff --git a/S2OJ/895/data/data4.out b/S2OJ/895/data/data4.out new file mode 100644 index 00000000..5ebe5c31 --- /dev/null +++ b/S2OJ/895/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b25f564a5bec747ae411e594d1af2d475049a31313872c2f44dfbe412f55293e +size 26599 diff --git a/S2OJ/895/data/data5.in b/S2OJ/895/data/data5.in new file mode 100644 index 00000000..1ce4e755 --- /dev/null +++ b/S2OJ/895/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:db41ace7d3f55193011ed005a70c3ac6a60fb66cf2ae8dfe69513bba00fbf241 +size 1154396 diff --git a/S2OJ/895/data/data5.out b/S2OJ/895/data/data5.out new file mode 100644 index 00000000..511d9542 --- /dev/null +++ b/S2OJ/895/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:080668ac0aec4061ecaa06b9945603d3cd7f787fa61e78c7b13be20deb8dfc5d +size 333094 diff --git a/S2OJ/895/data/data6.in b/S2OJ/895/data/data6.in new file mode 100644 index 00000000..abd3cb3e --- /dev/null +++ b/S2OJ/895/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b3f789ff503cfe9e5bd5ee15ac54bbf5b11771274965e3483e29914a483be12 +size 1153918 diff --git a/S2OJ/895/data/data6.out b/S2OJ/895/data/data6.out new file mode 100644 index 00000000..b113f0ad --- /dev/null +++ b/S2OJ/895/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c14cf8852d402fb5dd0dafec5e29441fcccbb3b991f1c3978ae6405363ff3755 +size 332741 diff --git a/S2OJ/895/data/data7.in b/S2OJ/895/data/data7.in new file mode 100644 index 00000000..2c6e5950 --- /dev/null +++ b/S2OJ/895/data/data7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a857298b07d8458a11a73f6bc6ac78ac65ac72ffa6ca21b40fa7a8b8c042567 +size 1154299 diff --git a/S2OJ/895/data/data7.out b/S2OJ/895/data/data7.out new file mode 100644 index 00000000..d0bf5934 --- /dev/null +++ b/S2OJ/895/data/data7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a93c52e97dc9b959b426a84a8afb51915040bfdde2ecaa35c96a066400ef7207 +size 333165 diff --git a/S2OJ/895/data/data8.in b/S2OJ/895/data/data8.in new file mode 100644 index 00000000..8bffc965 --- /dev/null +++ b/S2OJ/895/data/data8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7514b64901d4fc9fe304ead812cc00b62ab649d90ed0eabb4d9ce56630ee605f +size 1154143 diff --git a/S2OJ/895/data/data8.out b/S2OJ/895/data/data8.out new file mode 100644 index 00000000..d1f63919 --- /dev/null +++ b/S2OJ/895/data/data8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57b354b0ae89d355873008278ff5da288424cf94963839dd16f84057f8b456da +size 333186 diff --git a/S2OJ/895/data/data9.in b/S2OJ/895/data/data9.in new file mode 100644 index 00000000..2b7fe095 --- /dev/null +++ b/S2OJ/895/data/data9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3b4ce1724e32bd1416de3a96d1365073813902470105b9da7384a339ee9660e +size 2116113 diff --git a/S2OJ/895/data/data9.out b/S2OJ/895/data/data9.out new file mode 100644 index 00000000..852998a2 --- /dev/null +++ b/S2OJ/895/data/data9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d74386842a4b9175bdd7f753a55b303f088995fb64f5094e76ad41669e2ffbb +size 499654 diff --git a/S2OJ/895/data/problem.conf b/S2OJ/895/data/problem.conf new file mode 100644 index 00000000..b9dcf636 --- /dev/null +++ b/S2OJ/895/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45bb95dc6c0afd403ad6c457d15cbf7ce589f0789198b46f05e09ba72a7965ec +size 177