結果
問題 |
No.1891 Static Xor Range Composite Query
|
ユーザー |
👑 ![]() |
提出日時 | 2022-04-04 18:39:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 306 ms / 5,000 ms |
コード長 | 1,723 bytes |
コンパイル時間 | 874 ms |
コンパイル使用メモリ | 83,756 KB |
最終ジャッジ日時 | 2025-01-28 15:00:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) const u32 MOD = 998244353; struct F{ u32 a=1, b=0; u32 operator()(u32 x){ return ((u64)a*x + b) % MOD; } F operator+(F r){ return { (u32)(((u64)a*r.a) % MOD), (u32)(((u64)b*r.a+r.b) % MOD) }; } }; #include <tuple> struct Segtree{ int N, logN; vector<vector<F>> A; Segtree(vector<F> a){ int n = a.size(); N = 1; logN = 0; while(N < n){ N *= 2; logN++; } A.resize(logN+1); A[0] = a; A[0].resize(N); rep(d,logN){ auto tmp = A[d]; rep(i,N) if((i&(1<<d)) == 0){ tie(tmp[i], tmp[i|(1<<d)]) = make_pair( tmp[i] + tmp[i|(1<<d)], tmp[i|(1<<d)] + tmp[i] ); } A[d+1] = move(tmp); } } F prod(int l, int r, int x){ F ql, qr; int d = 0; while(l < r){ if(l & 1){ ql = ql + A[d][(l<<d)^x]; l++; } if(r & 1){ r--; qr = A[d][(r<<d)^x] + qr; } l /= 2; r /= 2; d++; } return ql + qr; } }; int main(){ int N, Q; cin >> N >> Q; vector<F> A(N); rep(i,N) cin >> A[i].a >> A[i].b; Segtree rq(A); rep(i,Q){ int l,r,p; u32 x; cin >> l >> r >> p >> x; u32 ans = rq.prod(l,r,p)(x); cout << ans << '\n'; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;