From 6fc48ed35f2ce9e9b442845c7e912db002406586 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 9 Feb 2023 09:33:22 +0800 Subject: [PATCH] =?UTF-8?q?P7432=20[THUPC2017]=20=E9=92=A6=E5=A6=B9?= =?UTF-8?q?=E7=9A=84=E7=8E=A9=E5=85=B7=E5=95=86=E5=BA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/101743741 --- Luogu/P7432/P7432.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Luogu/P7432/P7432.cpp diff --git a/Luogu/P7432/P7432.cpp b/Luogu/P7432/P7432.cpp new file mode 100644 index 00000000..f426bf09 --- /dev/null +++ b/Luogu/P7432/P7432.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int mod = 1e8 + 7; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + + cin >> t; + + while (t--) { + int n, m, q; + std::vector c{{0}}, v{{0}}, t{{0}}; + + cin >> n >> m >> q; + + std::copy_n(std::istream_iterator(cin), n, std::back_inserter(c)); + std::copy_n(std::istream_iterator(cin), n, std::back_inserter(v)); + std::copy_n(std::istream_iterator(cin), n, std::back_inserter(t)); + + std::vector>> vec(n + 1); + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= t[i]; j <<= 1) { + vec[i].emplace_back(c[i] * j, v[i] * j); + + t[i] -= j; + } + + if (t[i]) { + vec[i].emplace_back(c[i] * t[i], v[i] * t[i]); + } + } + + std::vector> + f(n + 2, std::vector(m + 2, 0)), + g(n + 2, std::vector(m + 2, 0)); + + for (int i = 1; i <= n; i++) { + for (int j = m; j >= 0; j--) { + f[i][j] = std::max(f[i][j], f[i - 1][j]); + } + + for (auto o : vec[i]) { + for (int j = m; j >= o.first; j--) { + f[i][j] = std::max(f[i][j], f[i][j - o.first] + o.second); + } + } + } + + for (int i = n; i; i--) { + for (int j = m; j >= 0; j--) { + g[i][j] = std::max(g[i][j], g[i + 1][j]); + } + + for (auto o : vec[i]) { + for (int j = m; j >= o.first; j--) { + g[i][j] = std::max(g[i][j], g[i][j - o.first] + o.second); + } + } + } + + int lst = 0; + + while (q--) { + int x, y; + + cin >> x >> y; + + int l = std::min((x + lst - 1) % n + 1, (y + lst - 1) % n + 1), + r = std::max((x + lst - 1) % n + 1, (y + lst - 1) % n + 1); + + int ans = 0, sum = 0; + std::vector h(m + 1); + + for (int i = 0; i <= m; i++) { + for (int j = 0; i + j <= m; j++) { + h[i + j] = std::max(h[i + j], f[l - 1][i] + g[r + 1][j]); + } + } + + for (int i = 1; i <= m; i++) { + ans = (ans + h[i]) % mod; + sum ^= h[i]; + } + + cout << (lst = ans) << ' ' << sum << endl; + } + } + + return 0; +}