結果
| 問題 |
No.1172 Add Recursive Sequence
|
| コンテスト | |
| ユーザー |
noshi91
|
| 提出日時 | 2020-05-09 19:33:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 236 ms / 4,000 ms |
| コード長 | 2,445 bytes |
| コンパイル時間 | 1,117 ms |
| コンパイル使用メモリ | 85,048 KB |
| 最終ジャッジ日時 | 2025-01-10 10:00:32 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 |
ソースコード
#include <cstdint>
template <std::uint_fast64_t mod> class modint {
using u64 = std::uint_fast64_t;
public:
u64 v;
constexpr modint(const u64 x = 0) noexcept : v(x % mod) {}
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
v += rhs.v;
if (v >= mod)
v -= mod;
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (v < rhs.v)
v += mod;
v -= rhs.v;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
v = v * rhs.v % mod;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
u64 exp = mod - 2;
while (exp != 0) {
if (exp % 2 != 0)
*this *= rhs;
rhs *= rhs;
exp /= 2;
}
return *this;
}
};
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
using mint = modint<1000000007>;
int k, n, m;
std::cin >> k >> n >> m;
std::vector<mint> a(k), c(k);
for (auto &e : a) {
std::cin >> e.v;
}
for (auto &e : c) {
std::cin >> e.v;
}
std::reverse(c.begin(), c.end());
// a_{n + k} まで計算する
a.resize(k + n, mint(0));
for (int i = 0; i < n; ++i) {
mint &t = a[i + k];
for (int j = 0; j < k; ++j) {
t += a[i + j] * c[j];
}
}
auto add = std::vector(n + 1, std::vector<int>());
auto sub = std::vector(n + 1, std::vector<int>());
for (int i = 0; i < m; ++i) {
int l, r;
std::cin >> l >> r;
add[l].push_back(0);
sub[r].push_back(r - l);
}
auto s = std::vector(k, mint(0));
for (int i = 0; i < n; ++i) {
// s を 1 つ進める
mint t = 0;
for (int j = 0; j < k; ++j) {
t += s[j] * c[j];
}
s.erase(s.begin());
s.push_back(t);
for (int l : add[i]) {
for (int j = 0; j < k; ++j) {
s[j] += a[l + j];
}
}
for (int l : sub[i]) {
for (int j = 0; j < k; ++j) {
s[j] -= a[l + j];
}
}
std::cout << s[0].v << "\n";
}
}
noshi91