結果
問題 | No.1068 #いろいろな色 / Red and Blue and more various colors (Hard) |
ユーザー | merom686 |
提出日時 | 2020-05-29 23:47:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 470 ms / 3,500 ms |
コード長 | 4,625 bytes |
コンパイル時間 | 1,638 ms |
コンパイル使用メモリ | 111,280 KB |
実行使用メモリ | 15,616 KB |
最終ジャッジ日時 | 2024-11-14 22:37:15 |
合計ジャッジ時間 | 11,673 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 11 ms
5,248 KB |
testcase_04 | AC | 6 ms
5,248 KB |
testcase_05 | AC | 6 ms
5,248 KB |
testcase_06 | AC | 6 ms
5,248 KB |
testcase_07 | AC | 6 ms
5,248 KB |
testcase_08 | AC | 6 ms
5,248 KB |
testcase_09 | AC | 7 ms
5,248 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 6 ms
5,248 KB |
testcase_12 | AC | 4 ms
5,248 KB |
testcase_13 | AC | 470 ms
15,360 KB |
testcase_14 | AC | 465 ms
15,360 KB |
testcase_15 | AC | 468 ms
15,488 KB |
testcase_16 | AC | 466 ms
15,616 KB |
testcase_17 | AC | 466 ms
15,360 KB |
testcase_18 | AC | 470 ms
15,488 KB |
testcase_19 | AC | 463 ms
15,488 KB |
testcase_20 | AC | 468 ms
15,488 KB |
testcase_21 | AC | 466 ms
15,488 KB |
testcase_22 | AC | 470 ms
15,488 KB |
testcase_23 | AC | 465 ms
15,360 KB |
testcase_24 | AC | 464 ms
15,568 KB |
testcase_25 | AC | 464 ms
15,488 KB |
testcase_26 | AC | 464 ms
15,488 KB |
testcase_27 | AC | 459 ms
15,488 KB |
testcase_28 | AC | 464 ms
15,488 KB |
testcase_29 | AC | 447 ms
15,616 KB |
testcase_30 | AC | 448 ms
15,488 KB |
testcase_31 | AC | 2 ms
5,248 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; 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 inv(int n) { int m = P, y = 0, v = 1; while (1) { int q = m / n; int r = m % n; if (r == 0) return v < 0 ? v + P : v; y -= v * q; swap(y, v); m = n; n = r; } } 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 i, int k, int sign) { if (k > 2) { if (sign > 0) { fmt_f(k, &data_[i], &w_[n_ * 1 - k]); } else { fmt_t(k, &data_[i], &w_[n_ * 2 - k]); } } } //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_); // } //} static inline uint32_t 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 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 l = FMT::get_2(n * 4); FMT::init(l); FMT p; for (int i = 0; i < n * 4; i += 4) { ll a; cin >> a; p[i + 0] = (a - 1) % FMT::P; p[i + 1] = 1; } for (int i = n * 4; i < l; i += 4) { p[i + 0] = 1; } for (int k = 4; k < l; k *= 2) { int k_inv = FMT::inv(k); for (int i = 0; i < l; i += k * 2) { p.fmt(i + 0, k, +1); p.fmt(i + k, k, +1); for (int j = i; j < i + k; j++) { p[j] = FMT::mul(p[j], p[j + k]); } p.fmt(i + 0, k, -1); for (int j = i; j < i + k; j++) { p[j] = FMT::mul(p[j], k_inv); p[j + k] = 0; //cout << p[j] << ' '; } //cout << '\n'; } } for (int i = 0; i < q; i++) { int b; cin >> b; cout << p[b] << '\n'; } return 0; }