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; +}