結果
問題 | No.1068 #いろいろな色 / Red and Blue and more various colors (Hard) |
ユーザー | merom686 |
提出日時 | 2020-05-30 01:58:12 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 489 ms / 3,500 ms |
コード長 | 4,633 bytes |
コンパイル時間 | 1,714 ms |
コンパイル使用メモリ | 113,076 KB |
実行使用メモリ | 11,452 KB |
最終ジャッジ日時 | 2024-11-14 22:36:52 |
合計ジャッジ時間 | 11,944 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 7 ms
5,248 KB |
testcase_04 | AC | 6 ms
5,248 KB |
testcase_05 | AC | 7 ms
5,248 KB |
testcase_06 | AC | 4 ms
5,248 KB |
testcase_07 | AC | 4 ms
5,248 KB |
testcase_08 | AC | 6 ms
5,248 KB |
testcase_09 | AC | 6 ms
5,248 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 4 ms
5,248 KB |
testcase_12 | AC | 3 ms
5,248 KB |
testcase_13 | AC | 463 ms
11,392 KB |
testcase_14 | AC | 465 ms
11,392 KB |
testcase_15 | AC | 463 ms
11,392 KB |
testcase_16 | AC | 465 ms
11,424 KB |
testcase_17 | AC | 489 ms
11,316 KB |
testcase_18 | AC | 463 ms
11,252 KB |
testcase_19 | AC | 489 ms
11,380 KB |
testcase_20 | AC | 463 ms
11,404 KB |
testcase_21 | AC | 465 ms
11,344 KB |
testcase_22 | AC | 464 ms
11,404 KB |
testcase_23 | AC | 463 ms
11,412 KB |
testcase_24 | AC | 464 ms
11,452 KB |
testcase_25 | AC | 463 ms
11,424 KB |
testcase_26 | AC | 462 ms
11,408 KB |
testcase_27 | AC | 462 ms
11,392 KB |
testcase_28 | AC | 464 ms
11,344 KB |
testcase_29 | AC | 478 ms
11,412 KB |
testcase_30 | AC | 449 ms
11,436 KB |
testcase_31 | AC | 2 ms
6,820 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #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; 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 inv(int n) { return P - (P - 1) / n; } static int get_2(int n) { int r = 1; while (r < n) r *= 2; return r; } FMT(int n) : 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 i, int n, int sign) { if (n > 2) { if (sign > 0) { fmt_f(n, &data_[i], &w_[n_ * 1 - n]); } else { fmt_t(n, &data_[i], &w_[n_ * 2 - n]); } } else if (n == 2) { fmt_2(&data_[i]); } } void conv(int i0, int i1, int n) { fmt(i0, n, +1); fmt(i1, n, +1); for (int i = 0; i < n; i++) { data_[i0 + i] = FMT::mul(data_[i0 + i], data_[i1 + i]); } fmt(i0, n, -1); const int n_inv = P - (P - 1) / n; for (int i = 0; i < n; i++) { data_[i0 + i] = FMT::mul(data_[i0 + i], n_inv); data_[i1 + i] = 0; } } 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 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 m = (n + 2) / 3; int l = FMT::get_2(m * 8); FMT::init(l / 2); FMT p(l); for (int i = 0; i < m * 8; i += 8) { ll b[3]; for (int j = 0; j < 3; j++) { ll a; if (n-- > 0) b[j] = (cin >> a, (a - 1) % FMT::P); } if (n >= 0) { p[i + 0] = b[0] * b[1] % FMT::P * b[2] % FMT::P; p[i + 1] = ((b[0] + b[1]) * b[2] + b[0] * b[1]) % FMT::P; p[i + 2] = (b[0] + b[1] + b[2]) % FMT::P; p[i + 3] = 1; } else if (n == -1) { p[i + 0] = b[0] * b[1] % FMT::P; p[i + 1] = (b[0] + b[1]) % FMT::P; p[i + 2] = 1; } else if (n == -2) { p[i + 0] = b[0]; p[i + 1] = 1; } } for (int i = m * 8; i < l; i += 8) { p[i] = 1; } for (int k = 8; k < l; k *= 2) { for (int i = 0; i < l; i += k * 2) { p.conv(i, i + k, k); } } while (q--) { int b; cin >> b; cout << p[b] << '\n'; } return 0; }