結果
問題 | No.1172 Add Recursive Sequence |
ユーザー | fastmath |
提出日時 | 2020-08-16 22:52:30 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 805 ms / 4,000 ms |
コード長 | 3,762 bytes |
コンパイル時間 | 2,284 ms |
コンパイル使用メモリ | 164,592 KB |
実行使用メモリ | 168,916 KB |
最終ジャッジ日時 | 2024-10-11 10:44:42 |
合計ジャッジ時間 | 7,200 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 130 ms
166,528 KB |
testcase_01 | AC | 131 ms
166,656 KB |
testcase_02 | AC | 132 ms
166,528 KB |
testcase_03 | AC | 130 ms
166,656 KB |
testcase_04 | AC | 129 ms
166,644 KB |
testcase_05 | AC | 130 ms
166,528 KB |
testcase_06 | AC | 133 ms
166,656 KB |
testcase_07 | AC | 129 ms
166,656 KB |
testcase_08 | AC | 131 ms
166,656 KB |
testcase_09 | AC | 131 ms
166,656 KB |
testcase_10 | AC | 144 ms
166,912 KB |
testcase_11 | AC | 145 ms
167,040 KB |
testcase_12 | AC | 141 ms
166,856 KB |
testcase_13 | AC | 140 ms
166,784 KB |
testcase_14 | AC | 241 ms
168,904 KB |
testcase_15 | AC | 199 ms
168,900 KB |
testcase_16 | AC | 805 ms
168,916 KB |
testcase_17 | AC | 702 ms
168,912 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; const int N = 1e5+7, MOD = 1e9+7; //need define int long long int mod(int n) { n %= MOD; if (n < 0) return n + MOD; else return n; } int fp(int a, int p) { int ans = 1, c = a; for (int i = 0; (1ll << i) <= p; ++i) { if ((p >> i) & 1) ans = mod(ans * c); c = mod(c * c); } return ans; } int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); } struct M { ll x; M (int x_) { x = mod(x_); } M () { x = 0; } M operator + (M y) { int ans = x + y.x; if (ans >= MOD) ans -= MOD; return M(ans); } M operator - (M y) { int ans = x - y.x; if (ans < 0) ans += MOD; return M(ans); } M operator * (M y) { return M(x * y.x % MOD); } M operator / (M y) { return M(x * fp(y.x, MOD - 2) % MOD); } M operator + (int y) { return (*this) + M(y); } M operator - (int y) { return (*this) - M(y); } M operator * (int y) { return (*this) * M(y); } M operator / (int y) { return (*this) / M(y); } M operator ^ (int p) { return M(fp(x, p)); } void operator += (M y) { *this = *this + y; } void operator -= (M y) { *this = *this - y; } void operator *= (M y) { *this = *this * y; } void operator /= (M y) { *this = *this / y; } void operator += (int y) { *this = *this + y; } void operator -= (int y) { *this = *this - y; } void operator *= (int y) { *this = *this * y; } void operator /= (int y) { *this = *this / y; } void operator ^= (int p) { *this = *this ^ p; } }; M f[N], inv[N]; void prec() { f[0] = M(1); for (int i = 1; i < N; ++i) f[i] = f[i - 1] * M(i); inv[N - 1] = f[N - 1] ^ (MOD - 2); for (int i = N - 2; i >= 0; --i) inv[i] = inv[i + 1] * M(i + 1); } M C(int n, int k) { if (n < k) return M(0); else return f[n] * inv[k] * inv[n - k]; } const int K = 207; M up[N][K]; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif int k, n, m; cin >> k >> n >> m; vector <M> a(k); for (int i = 0; i < k; ++i) cin >> a[i].x; vector <M> c(k); for (int i = 0; i < k; ++i) cin >> c[i].x; while (a.size() <= n) { M x(0); int sz = a.size(); for (int i = 0; i < k; ++i) x += c[i] * a[sz - i - 1]; a.app(x); } #ifdef HOME for (auto e : a) cout << e.x << endl; cout << endl; #endif vector <M> add(n); for (int i = 0; i < m; ++i) { int l, r; cin >> l >> r; r--; int len = r - l + 1; for (int j = 0; j < min(len, k); ++j) { add[l + j] += a[j]; } if (len >= k) { for (int i = 0; i < k; ++i) up[l + k][i] += a[i]; for (int i = 0; i < k; ++i) up[r + 1][i] -= a[r + 1 - l - k + i]; } } vector <M> lf(n); for (int i = 0; i < n; ++i) { if (i >= k) { for (int j = 0; j < k; ++j) lf[i - k + j] += up[i][j]; for (int j = 0; j < k; ++j) lf[i] += lf[i - 1 - j] * c[j]; } cout << (lf[i] + add[i]).x << endl; } }