結果
問題 | No.1307 Rotate and Accumulate |
ユーザー | merom686 |
提出日時 | 2020-12-04 01:10:11 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 57 ms / 5,000 ms |
コード長 | 3,899 bytes |
コンパイル時間 | 1,278 ms |
コンパイル使用メモリ | 96,684 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-09-14 11:04:18 |
合計ジャッジ時間 | 3,167 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 39 ms
7,168 KB |
testcase_09 | AC | 42 ms
7,296 KB |
testcase_10 | AC | 34 ms
5,376 KB |
testcase_11 | AC | 24 ms
6,940 KB |
testcase_12 | AC | 33 ms
5,376 KB |
testcase_13 | AC | 10 ms
5,376 KB |
testcase_14 | AC | 18 ms
5,376 KB |
testcase_15 | AC | 56 ms
7,296 KB |
testcase_16 | AC | 57 ms
7,168 KB |
testcase_17 | AC | 56 ms
7,168 KB |
testcase_18 | AC | 50 ms
7,168 KB |
testcase_19 | AC | 57 ms
7,296 KB |
testcase_20 | AC | 57 ms
7,296 KB |
testcase_21 | AC | 2 ms
5,376 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> using namespace std; using ll = long long; class FMT { public: static constexpr uint32_t W = 31, P = (119 << 23) + 1; static void init(int n) { if ((n & -n) != n || n < 1) throw; n_ = n; n_inv_ = P - P / n_; if (n_ < 4) return; w_.resize(n_ * 2); uint32_t w1 = W; for (int n = n_; n < 1 << 23; n *= 2) { w1 = mul(w1, w1); } for (int l = 0; l < 2; l++) { uint32_t *w = &w_[l * n_]; w[0] = 1; for (int i = 1; i < n_ / 2; i++) { w[i] = mul(w[i - 1], w1); } for (int i = 0; i < n_ / 2; i++) { w[n_ / 2 + i] = w[i * 2]; } w1 = mul(w_[n_ / 2 - 1], mul(w_[n_ / 4], w_[n_ / 4])); } } static int get_2(int n) { int r = 1; while (r < n) r *= 2; return r; } FMT() : data_(n_, 0) {} static uint32_t add(uint32_t a1, uint32_t a2) { const uint32_t t = a1 + a2; return t < P ? t : t - P; } static uint32_t sub(uint32_t a1, uint32_t a2) { const uint32_t t = a1 - a2; return t < P ? t : t + P; } static uint32_t mul(uint32_t a1, uint32_t a2) { return (uint64_t)a1 * a2 % P; } uint32_t &operator[](size_t i) { return data_[i]; } void fmt(int sign) { if (n_ > 2) { if (sign > 0) { fmt_f(n_, &data_[0], &w_[0]); } else { fmt_t(n_, &data_[0], &w_[n_]); } } else if (n_ == 2) { fmt_2(&data_[0]); } } void conv(FMT &b) { fmt(+1); if (this != &b) b.fmt(+1); for (int i = 0; i < n_; i++) { data_[i] = mul(data_[i], b.data_[i]); } fmt(-1); for (int i = 0; i < n_; i++) { data_[i] = mul(data_[i], n_inv_); } } private: static void fmt_f(int n, uint32_t *p, uint32_t *w) { const int m = n / 2; for (int i = 0; i < m; i++) { const int j = i + m; const uint32_t t0 = add(p[i], p[j]); const uint32_t t1 = mul(p[i] - p[j] + P, w[i]); p[i] = t0; p[j] = t1; } if (m == 2) { fmt_2(p); fmt_2(p + 2); } else { fmt_f(m, p, w + m); fmt_f(m, p + m, w + m); } } static void fmt_t(int n, uint32_t *p, uint32_t *w) { const int m = n / 2; if (m == 2) { fmt_2(p); fmt_2(p + 2); } else { fmt_t(m, p, w + m); fmt_t(m, p + m, w + m); } for (int i = 0; i < m; i++) { int j = i + m; const uint32_t t0 = mul(w[i], p[j]); p[j] = sub(p[i], t0); p[i] = add(p[i], t0); } } static void fmt_2(uint32_t *p) { const uint32_t t0 = add(p[0], p[1]); const uint32_t t1 = sub(p[0], p[1]); p[0] = t0; p[1] = t1; } static inline int n_; static inline uint32_t n_inv_; static inline vector<uint32_t> w_; vector<uint32_t> data_; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; int k = FMT::get_2(n) * 2; FMT::init(k); FMT p[2]; for (int i = 0; i < n; i++) { int a; cin >> a; p[0][i] = a; } for (int j = 0; j < q; j++) { int r; cin >> r; if (r > 0) r = n - r; p[1][r]++; } for (int i = 1; i < n; i++) { p[1][i + k - n] = p[1][i]; } p[0].conv(p[1]); for (int i = 0; i < n; i++) { cout << p[0][i] << " \n"[i == n - 1]; } return 0; }