結果
| 問題 |
No.2265 Xor Range Substring Sum Query
|
| コンテスト | |
| ユーザー |
とりゐ
|
| 提出日時 | 2023-03-12 16:28:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 814 ms / 5,000 ms |
| コード長 | 1,566 bytes |
| コンパイル時間 | 2,029 ms |
| コンパイル使用メモリ | 197,936 KB |
| 最終ジャッジ日時 | 2025-02-11 10:40:19 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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];
int n,N,m,l,r;
S op(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]=op(node[i-1][L],node[i-1][R]);
}
void build(){
for(int i=0;i<m;i++){
for(int j=0;j<N;j++){
merge(i+1,j);
}
}
}
void update(int x,S k){
node[0][x]=k;
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);
}
}
}
S E={0,0};
S query(int L,int R,int X){
S ans=E;
for(int i=0;i<m;i++){
if(((L>>i)&1)&&(L+(1<<i)<=R)){
ans=op(ans,node[i][L^X]);
L+=1<<i;
}
}
while(L+(1<<m)<=R){
ans=op(ans,node[m][L^X]);
L+=1<<m;
}
for(int i=m-1;i>=0;--i){
if(L+(1<<i)<=R){
ans=op(ans,node[i][L^X]);
L+=1<<i;
}
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n;
N=1<<n;
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;
}
build();
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';
}
}
}
とりゐ