結果
問題 | No.2265 Xor Range Substring Sum Query |
ユーザー | 👑 Nachia |
提出日時 | 2023-04-07 22:07:50 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 977 ms / 5,000 ms |
コード長 | 2,672 bytes |
コンパイル時間 | 1,093 ms |
コンパイル使用メモリ | 87,020 KB |
実行使用メモリ | 7,644 KB |
最終ジャッジ日時 | 2024-10-02 19:37:37 |
合計ジャッジ時間 | 11,433 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <atcoder/modint> 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 i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; int main(){ int N; string S; cin >> N >> S; vector<int> Sval(1<<N); rep(i,1<<N) Sval[i] = S[i] - '0'; int n = N/2; vector<Modint> pow10((1<<N)+1); pow10[0] = 1; rep(i,1<<N) pow10[i+1] = pow10[i] * 11; vector<Modint> pow2((1<<N)+1); pow2[0] = 1; rep(i,1<<N) pow2[i+1] = pow2[i] * 2; const int SZ = 1 << (N-n); const int MASK = SZ - 1; vector<vector<Modint>> micro(1<<n, vector<Modint>(SZ)); rep(i,1<<n){ rep(j,SZ) micro[i][j] = Sval[(i<<(N-n))+j]; rep(d,N-n) rep(j,SZ) if(!(j&(1<<d))){ auto& a = micro[i][j]; auto& b = micro[i][j|(1<<d)]; Modint ab = a * pow10[1<<d] + b * pow2[1<<d]; Modint ba = a * pow2[1<<d] + b * pow10[1<<d]; a = ab; b = ba; } } auto naive = [&](int l, int r, int x) -> Modint { Modint ans; for(int i=l; i<r; i++){ ans += Modint::raw(Sval[i^x]) * pow2[i-l] * pow10[r-1-i]; } return ans; }; int Q; cin >> Q; rep(q,Q){ int t; cin >> t; if(t == 1){ int x, y; cin >> x >> y; y -= Sval[x]; Sval[x] += y; Modint dy = y; int i = x >> (N-n); auto iter = micro[i].begin(); int xx = x & MASK; rep(j,SZ) iter[j] += dy * pow2[xx^j] * pow10[SZ-1-(xx^j)]; } else if(t == 2){ int l, r, x; cin >> l >> r >> x; r++; Modint ans = 0; if(r - l <= SZ * 2){ ans = naive(l, r, x); } else{ int lv = (l + (SZ - 1)) >> (N-n); int rv = r >> (N-n); int lowmask = x & MASK; int himask = x >> (N-n); ans += naive(l, lv << (N-n), x) * pow10[r - (lv << (N-n))]; for(int d=lv; d<rv; d++){ ans += micro[d^himask][lowmask] * pow2[(d<<(N-n))-l] * pow10[r-((d+1)<<(N-n))]; } ans += naive(rv << (N-n), r, x) * pow2[(rv << (N-n)) - l]; } cout << ans.val() << '\n'; } } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;