結果
問題 |
No.2265 Xor Range Substring Sum Query
|
ユーザー |
![]() |
提出日時 | 2023-03-12 16:20:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 698 ms / 5,000 ms |
コード長 | 1,560 bytes |
コンパイル時間 | 1,686 ms |
コンパイル使用メモリ | 198,700 KB |
最終ジャッジ日時 | 2025-02-11 10:40:00 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> #define elif else if using mint=atcoder::modint998244353; using S=pair<mint,int>; mint pow11[1<<18]; mint pow2[1<<18]; S node[10][1<<18]; S calc(S L,S R){ return {L.first*pow11[R.second]+R.first*pow2[L.second],L.second+R.second}; } void merge(int i,int j){ int L=j; int R=L^(1<<(i-1)); node[i][L]=calc(node[i-1][L],node[i-1][R]); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; int N=1<<n; int m=n/2; string s; cin>>s; for(int i=0;i<N;i++){ node[0][i]={s[i]-'0',1}; } pow11[0]=1; pow2[0]=1; for(int i=1;i<=N;i++){ pow11[i]=pow11[i-1]*11; pow2[i]=pow2[i-1]*2; } for(int i=0;i<m;i++){ for(int j=0;j<N;j++){ merge(i+1,j); } } int q,t,x,y,L,R,X,l,r; cin>>q; for(int tc=0;tc<q;tc++){ cin>>t; if(t==1){ cin>>x>>y; node[0][x]={y,1}; for(int i=0;i<m;i++){ l=(x>>(i+1))<<(i+1); r=l+(1<<(i+1)); for(int j=l;j<r;j++){ merge(i+1,j); } } } else{ cin>>L>>R>>X; R++; S ans={0,0}; for(int i=0;i<m;i++){ if(((L>>i)&1)&&(L+(1<<i)<=R)){ ans=calc(ans,node[i][L^X]); L+=1<<i; } } while(L+(1<<m)<=R){ ans=calc(ans,node[m][L^X]); L+=1<<m; } for(int i=m-1;i>=0;--i){ if(L+(1<<i)<=R){ ans=calc(ans,node[i][L^X]); L+=1<<i; } } cout<<ans.first.val()<<'\n'; } } }