結果
| 問題 |
No.1172 Add Recursive Sequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-11 17:19:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 244 ms / 4,000 ms |
| コード長 | 4,029 bytes |
| コンパイル時間 | 2,034 ms |
| コンパイル使用メモリ | 205,456 KB |
| 最終ジャッジ日時 | 2025-02-07 04:19:20 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 |
ソースコード
#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" ;
}