結果

問題 No.1172 Add Recursive Sequence
ユーザー Div9851Div9851
提出日時 2021-01-13 23:39:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,296 ms / 4,000 ms
コード長 1,920 bytes
コンパイル時間 2,463 ms
コンパイル使用メモリ 199,860 KB
実行使用メモリ 162,204 KB
最終ジャッジ日時 2023-08-14 20:12:44
合計ジャッジ時間 6,454 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 4 ms
6,740 KB
testcase_07 AC 3 ms
6,728 KB
testcase_08 AC 4 ms
6,784 KB
testcase_09 AC 3 ms
6,660 KB
testcase_10 AC 17 ms
31,684 KB
testcase_11 AC 16 ms
33,676 KB
testcase_12 AC 15 ms
29,484 KB
testcase_13 AC 15 ms
29,460 KB
testcase_14 AC 119 ms
162,204 KB
testcase_15 AC 83 ms
162,056 KB
testcase_16 AC 1,296 ms
161,952 KB
testcase_17 AC 674 ms
161,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

ll a[100000], c[201];
ll sum[100000][201];
ll imos[100000];

int main() {
    int K, N, M;
    cin >> K >> N >> M;
    for (int i = 0; i < K; i++) {
        cin >> a[i];
        a[i] %= MOD;
    }
    for (int i = 1; i <= K; i++) {
        cin >> c[i];
        c[i] %= MOD;
    }
    for (int i = 0; i < N; i++) {
        sum[i][0] = 0;
        for (int j = 1; j <= K; j++) {
            (sum[i][j] += sum[i][j - 1]) %= MOD;
            if (i >= j)
                (sum[i][j] += c[j] * a[i - j] % MOD) %= MOD;
        }
        if (i >= K)
            a[i] = sum[i][K];
    }
    for (int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        for (int j = 0; j < K; j++) {
            if (l + j >= N)
                break;
            ll add = a[j];
            (add += MOD - sum[j][j]) %= MOD;
            (imos[l + j] += add) %= MOD;
        }
        for (int j = 0; j < K; j++) {
            if (r + j >= N)
                break;
            ll sub = a[r - l + j];
            (sub += MOD - sum[r - l + j][j]) %= MOD;
            (imos[r + j] += MOD - sub) %= MOD;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            if (j > i)
                break;
            (imos[i] += c[j] * imos[i - j] % MOD) %= MOD;
        }
    }
    for (int i = 0; i < N; i++)
        cout << imos[i] << '\n';
}
0