From 1beb2efb0aafb2cc0eaa7c1ebf9155a9da05be0b Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Wed, 27 Apr 2016 20:34:30 +0800 Subject: [PATCH] From http://blog.csdn.net/qq_33765907/article/details/51228610 --- ZOJ/3940_csdn.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ZOJ/3940_csdn.cpp diff --git a/ZOJ/3940_csdn.cpp b/ZOJ/3940_csdn.cpp new file mode 100644 index 0000000..f633f79 --- /dev/null +++ b/ZOJ/3940_csdn.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; +const int MAXN = 100000 + 10, M = 1e9 + 7; +int a[MAXN], n, m; +map last; + +void run() { + scanf("%d%d", &n, &m); + last.clear(); last[m] = 1; + for (int i = 0; i < n; ++i) { + int x, s = 0; scanf("%d", &x); + auto it = last.lower_bound(x); + for (; it != last.end(); ) { + last[it->first % x] += it->second; + s += it->second * (it->first / x); + it = last.erase(it); + } + if (s) last[x - 1] += s; + } + int s = 0; + for (auto it = last.rbegin(); it != last.rend(); ++it) { + it->second += s; s = it->second; + } + int q, ret = 0; scanf("%d", &q); + for (int i = 1; i <= q; ++i) { + int x; scanf("%d", &x); + auto it = last.lower_bound(x); + if (it != last.end()) ret += 1ll * it->second * i % M; + if (ret >= M) ret -= M; + } + printf("%d\n", ret); +} + +int main() { + int T; scanf("%d", &T); + for (int cas = 1; cas <= T; ++cas) run(); + return 0; +}