結果

問題 No.1172 Add Recursive Sequence
ユーザー optopt
提出日時 2020-08-28 14:18:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 483 ms / 4,000 ms
コード長 1,901 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 201,140 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-26 10:37:40
合計ジャッジ時間 4,204 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 8 ms
5,376 KB
testcase_12 AC 9 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 52 ms
6,144 KB
testcase_15 AC 47 ms
6,016 KB
testcase_16 AC 483 ms
6,016 KB
testcase_17 AC 439 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
const int MOD = int(1e9) + 7;


template<int MOD> struct ModInt {
  int x;
  ModInt(int _x = 0) : x( (0 <= _x && _x < MOD) ? _x : (_x%MOD+MOD)%MOD ) {}
  constexpr ModInt operator-() const noexcept { return ModInt(MOD-x); }
  constexpr ModInt operator+(const ModInt y) const noexcept { return ModInt(*this) += y; }
  constexpr ModInt operator-(const ModInt y) const noexcept { return ModInt(*this) -= y; }
  constexpr ModInt operator*(const ModInt y) const noexcept { return ModInt(*this) *= y; }
  constexpr ModInt &operator+=(const ModInt y) noexcept { x += y.x; if (x >= MOD) x -= MOD; return *this; }
  constexpr ModInt &operator-=(const ModInt y) noexcept { x -= y.x; if (x < 0) x += MOD; return *this; }
  constexpr ModInt &operator*=(const ModInt y) noexcept { x = ll(x) * y.x % MOD; return *this; }
};
using mint = ModInt<MOD>;
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }


int main() {
  int k, n, m; cin >> k >> n >> m;
  vector<mint> a(n), c(k+1);
  c[0] = -1;
  rep(i, k) cin >> a[i];
  rep(i, k) cin >> c[i+1];
  rep2(i, k, n) rep2(j, 1, k+1) a[i] += c[j]*a[i-j];

  vector<array<int, 2>> add(m), sub(m);
  rep(i, m) {
    int l, r; cin >> l >> r;
    add[i] = {l, 0};
    sub[i] = {r, r-l};
  }

  vector<mint> b(n+1), p(n);
  rep(i, k) {
    rep(j, n) b[j] = b[j+1] + c[i]*a[j];
    for (auto &[l, s] : add) if (l+i < n) p[l+i] += b[s];
    for (auto &[l, s] : sub) if (l+i < n) p[l+i] -= b[s];
  }

  rep(i, n) {
    rep2(j, 1, min(k, i)+1) p[i] -= c[j]*p[i-j];
    p[i] = -p[i];
    cout << p[i] << '\n';
  }
}
0