結果

問題 No.1172 Add Recursive Sequence
ユーザー optopt
提出日時 2020-04-26 19:26:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,879 bytes
コンパイル時間 2,009 ms
コンパイル使用メモリ 198,484 KB
実行使用メモリ 818,176 KB
最終ジャッジ日時 2024-04-17 06:55:00
合計ジャッジ時間 7,359 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
const int MOD = int(1e9) + 7;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint& operator/=(const mint r) {
    ll a = r.x, b = MOD, u = 1, v = 0;
    while (b) {
      ll t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    x = x * u % MOD;
    if (x < 0) x += MOD;
    return *this;
  }
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

using Vm = vector<mint>;


int main() {
  ll k, n, m; cin >> k >> n >> m;
  Vm a(k+n);
  rep(i, k) cin >> a[i];

  Vm c(k+1);
  c[0] = -1;
  rep(i, k) cin >> c[i+1];

  rep2(i, k, n+k) rep2(j, 1, k+1) a[i] += c[j]*a[i-j];

  Vm y(n);
  rep(_, m) {
    int l, r; cin >> l >> r;
    rep(i, k) rep(j, k-i) if (l+i+j < n) y[l+i+j] -= c[i] * a[j];
    rep(i, k) rep(j, k-i) if (r+i+j < n) y[r+i+j] += c[i] * a[r-l+j];
  }

  Vm x(n+k);
  rep(i, n) {
    x[k+i] = y[i];
    rep2(j, 1, k+1) x[k+i] += c[j] * x[k+i-j];
    cout << x[k+i] << endl;
  }
  return 0;
}
0