結果
| 問題 |
No.1307 Rotate and Accumulate
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-02 08:35:30 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 5,000 ms |
| コード長 | 1,903 bytes |
| コンパイル時間 | 3,786 ms |
| コンパイル使用メモリ | 281,716 KB |
| 実行使用メモリ | 12,460 KB |
| 最終ジャッジ日時 | 2025-10-02 08:35:37 |
| 合計ジャッジ時間 | 6,492 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); i ++)
using std::cin, std::cout, std::cerr;
using ll = long long;
const ll P = 998244353, G = 3;
ll qpow(ll a, ll b) {
ll r = 1;
for(; b; b /= 2) {
if(b & 1)
r = r * a % P;
a = a * a % P;
}
return r;
}
ll INV(ll x) { return qpow(x, P - 2); }
using vl = std::vector<ll>;
void ntt(vl &a, int op = 1) { // P: 模数, G: 原根
int n = a.size();
for (int i = 1, j = 0; i < n - 1; ++i) {
for (int s = n; j ^= s >>= 1, ~j & s;) {}
if (i < j) std::swap(a[i], a[j]);
}
for (int i = 1; i < n; i *= 2) {
ll u = qpow(G, (P - 1) / (i * 2));
if (op == -1) u = INV(u);
for (int j = 0; j < n; j += i * 2) {
ll w = 1;
for (int k = 0; k < i; ++k, w = w * u % P) {
int x = a[j + k], y = w * a[j + k + i] % P;
#define modto(x) ({if ((x) >= P) (x) -= P;})
a[j + k] = x + y; modto(a[j + k]);
a[j + k + i] = x - y + P; modto(a[j + k + i]);
#undef modto
}}}
if (op == -1) { ll inv = INV(n);
for (int i = 0; i < n; ++i) a[i] = a[i] * inv % P; }
}
vl multi(vl a, vl b) {
int m = a.size() + b.size() - 1;
int n = 1; while (n < m) n *= 2;
vl fa(n), fb(n), fc(n);
std::copy(a.begin(), a.end(), fa.begin()); ntt(fa);
std::copy(b.begin(), b.end(), fb.begin()); ntt(fb);
for (int i = 0; i < n; ++i) fc[i] = fa[i] * fb[i] % P;
ntt(fc, -1); fc.resize(m);
return fc;
}
int main() {
std::ios::sync_with_stdio(false);
int n, q; cin >> n >> q;
std::vector<ll> a(n), b(n);
rep(i, 0, n - 1) cin >> a[i];
while(q --) {
int x; cin >> x;
b[(n - x) % n] ++;
}
auto c = multi(a, b);
for(int i = n; i < c.size(); i ++)
c[i - n] += c[i];
rep(i, 0, n - 1)
cout << c[i] << ' ';
cout << '\n';
}