結果
問題 |
No.1891 Static Xor Range Composite Query
|
ユーザー |
|
提出日時 | 2022-07-12 02:58:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 749 ms / 5,000 ms |
コード長 | 1,838 bytes |
コンパイル時間 | 1,036 ms |
コンパイル使用メモリ | 79,516 KB |
最終ジャッジ日時 | 2025-01-30 06:40:14 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include <iostream> #include <vector> #include <atcoder/modint> using mint = atcoder::modint998244353; struct F { mint a, b; static F op(F f, F g) { return F{ g.a * f.a, g.a * f.b + g.b }; } static F e() { return F{ 1, 0 }; } mint eval(mint x) { return a * x + b; } }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, q; std::cin >> n >> q; std::vector<std::vector<F>> seg(2 * n); for (int i = 0; i < n; ++i) { int a, b; std::cin >> a >> b; seg[n + i] = { F { a, b } }; } for (int k = n - 1; k >= 1; --k) { const int siz = seg[2 * k].size(); seg[k].resize(2 * siz); for (int s = 0; s < siz; ++s) { seg[k][0 * siz + s] = F::op(seg[2 * k + 0][s], seg[2 * k + 1][s]); seg[k][1 * siz + s] = F::op(seg[2 * k + 1][s], seg[2 * k + 0][s]); } } auto query = [&](auto query, int ql, int qr, int tl, int tr, int k, int p, int bit) -> F { if (qr <= tl or tr <= ql) return F::e(); if (ql <= tl and tr <= qr) return seg[k][p]; const int flip = p & bit; const int tm = (tl + tr) >> 1; if (flip) { F sl = query(query, ql, qr, tl, tm, 2 * k + 1, p ^ flip, bit >> 1); F sr = query(query, ql, qr, tm, tr, 2 * k + 0, p ^ flip, bit >> 1); return F::op(sl, sr); } else { F sl = query(query, ql, qr, tl, tm, 2 * k + 0, p ^ flip, bit >> 1); F sr = query(query, ql, qr, tm, tr, 2 * k + 1, p ^ flip, bit >> 1); return F::op(sl, sr); } }; while (q --> 0) { int l, r, p, x; std::cin >> l >> r >> p >> x; std::cout << query(query, l, r, 0, n, 1, p, n >> 1).eval(x).val() << '\n'; } return 0; }