結果
問題 | No.2265 Xor Range Substring Sum Query |
ユーザー |
![]() |
提出日時 | 2023-03-12 03:21:21 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,487 ms / 5,000 ms |
コード長 | 2,093 bytes |
コンパイル時間 | 5,891 ms |
コンパイル使用メモリ | 259,696 KB |
最終ジャッジ日時 | 2025-02-11 10:33:10 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> #define elif else if #define ll long long using mint=atcoder::modint998244353; using S=pair<mint,int>; mint pow11[1<<18]; mint pow2[1<<18]; S node[19][1<<18]; int last_update[19][1<<18]; int lazy[1<<19]; int n,N,Time; S merge(S L,S R){ return {L.first*pow11[R.second]+R.first*pow2[L.second],L.second+R.second}; } void build(){ for(int i=0;i<=n;i++){ for(int j=0;j<N;j++){ last_update[i][j]=0; if(i!=0) node[i][j]=merge(node[i-1][j],node[i-1][j^(1<<(i-1))]); } } } void update(int x,S k){ node[0][x]=k; last_update[0][x]=Time; int res=x+N; for(int i=0;i<=n;i++){ lazy[res]=Time; res>>=1; } Time+=1; } S get(int i,int j){ //cout<<'?'<<' '<<i<<' '<<j<<endl; if(last_update[i][j]==lazy[(j+N)>>i]){ return node[i][j]; } node[i][j]=merge(get(i-1,j),get(i-1,j^(1<<(i-1)))); last_update[i][j]=lazy[(j+N)>>i]; return node[i][j]; } S E={0,0}; S query(int L,int R,int X){ S res=E; //cout<<'!'<<' '<<L<<' '<<R<<endl; for(int i=0;i<=n;i++){ if(((L>>i)&1)&&(L+(1<<i)<=R)){ res=merge(res,get(i,L^X)); L+=1<<i; //cout<<L<<' '<<res.first.val()<<' '<<res.second<<endl; } } for(int i=n;i>=0;--i){ if(L+(1<<i)<=R){ res=merge(res,get(i,L^X)); L+=1<<i; //cout<<L<<' '<<res.first.val()<<' '<<res.second<<endl; } } return res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin>>n; N=1<<n; Time=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<2*N;i++){ lazy[i]=0; } string s; cin>>s; for(int i=0;i<N;i++){ node[0][i]={s[i]-'0',1}; } build(); for(int i=0;i<=n;i++){ for(int j=0;j<N;j++){ //cout<<i<<' '<<j<<' '<<node[i][j].first.val()<<endl; } } int q,t,x,y,L,R,X; cin>>q; for(int tc=0;tc<q;tc++){ cin>>t; if(t==1){ cin>>x>>y; update(x,{y,1}); } else{ cin>>L>>R>>X; cout<<query(L,R+1,X).first.val()<<'\n'; } } }