結果

問題 No.1172 Add Recursive Sequence
ユーザー Suu0313Suu0313
提出日時 2022-09-11 17:19:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 4,000 ms
コード長 4,029 bytes
コンパイル時間 2,512 ms
コンパイル使用メモリ 210,488 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2023-08-18 19:40:26
合計ジャッジ時間 5,436 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 57 ms
9,596 KB
testcase_15 AC 37 ms
8,396 KB
testcase_16 AC 222 ms
9,728 KB
testcase_17 AC 198 ms
8,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template< int mod >
struct ModInt {
  int x;

  constexpr ModInt() : x(0) {}

  constexpr ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  
  constexpr ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  constexpr ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  constexpr ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  constexpr ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  constexpr bool operator==(const ModInt &p) const { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const { return x != p.x; }
  constexpr bool operator<(const ModInt &p) const { return x < p.x; }

  constexpr ModInt& operator++() { (*this).x+=1; return (*this); }
  constexpr ModInt& operator--() { (*this).x-=1; return (*this); }
  constexpr ModInt operator++(int) { ModInt tmp(*this); ++(*this); return tmp; }
  constexpr ModInt operator--(int) { ModInt tmp(*this); --(*this); return tmp; }

  constexpr ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul; n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  constexpr static int get_mod() { return mod; }
};
template< int mod >
constexpr ModInt<mod> operator+(const int64_t &p, const ModInt<mod> &m){ return ModInt<mod>(p) + m; };
template< int mod >
constexpr ModInt<mod> operator-(const int64_t &p, const ModInt<mod> &m){ return ModInt<mod>(p) - m; };
template< int mod >
constexpr ModInt<mod> operator*(const int64_t &p, const ModInt<mod> &m){ return ModInt<mod>(p) * m; };
template< int mod >
constexpr ModInt<mod> operator/(const int64_t &p, const ModInt<mod> &m){ return ModInt<mod>(p) / m; };

constexpr int MOD = 1e9 + 7;
using mint = ModInt< MOD >;
namespace mintliteral{ constexpr mint operator""_m(unsigned long long x) { return mint(x); } }
using namespace mintliteral;


template<typename T>
struct ArithmeticImos{
  int n, k;
  vector<vector<pair<int, T>>> query;

  ArithmeticImos() = default;
  ArithmeticImos(int n, int k): n(n), k(k), query(n + 1) {}

  void add(int l, int r, const T &x){
    query[l].emplace_back(0, x);
    query[r].emplace_back(r - l, -x);
  }

  vector<T> build(vector<T> a, vector<T> c){
    a.resize(n + k);
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < k; ++j){
        a[i + k] += a[i + j] * c[j];
      }
    }

    vector<T> s(k), res(n);
    for(int i = 0; i < n; ++i){
      T t = 0;
      for(int j = 0; j < k; ++j) t += s[j] * c[j];
      s.erase(begin(s)); s.push_back(t);

      for(auto[l, x] : query[i]){
        for(int j = 0; j < k; ++j) s[j] += a[l + j] * x;
      }

      res[i] = s[0];
    }
    return res;
  }
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int k, n, m; cin >> k >> n >> m;

  ArithmeticImos<mint> imos(n, k);

  vector<mint> a(k), c(k);
  for(auto&&e : a) cin >> e;
  for(auto&&e : c) cin >> e;
  reverse(begin(c), end(c));

  while(m--){
    int l, r; cin >> l >> r;
    imos.add(l, r, 1);
  }

  for(auto&&e : imos.build(a, c)) cout << e << "\n" ;
}
0