結果

問題 No.2265 Xor Range Substring Sum Query
ユーザー とりゐとりゐ
提出日時 2023-03-12 16:20:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 833 ms / 5,000 ms
コード長 1,560 bytes
コンパイル時間 2,768 ms
コンパイル使用メモリ 207,308 KB
実行使用メモリ 26,404 KB
最終ジャッジ日時 2023-10-25 05:08:43
合計ジャッジ時間 18,066 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
26,156 KB
testcase_01 AC 10 ms
26,156 KB
testcase_02 AC 11 ms
26,164 KB
testcase_03 AC 11 ms
26,164 KB
testcase_04 AC 653 ms
26,404 KB
testcase_05 AC 644 ms
26,404 KB
testcase_06 AC 638 ms
26,404 KB
testcase_07 AC 626 ms
26,404 KB
testcase_08 AC 633 ms
26,404 KB
testcase_09 AC 822 ms
26,404 KB
testcase_10 AC 833 ms
26,404 KB
testcase_11 AC 832 ms
26,404 KB
testcase_12 AC 804 ms
26,404 KB
testcase_13 AC 830 ms
26,404 KB
testcase_14 AC 803 ms
26,404 KB
testcase_15 AC 804 ms
26,404 KB
testcase_16 AC 808 ms
26,404 KB
testcase_17 AC 811 ms
26,404 KB
testcase_18 AC 326 ms
26,404 KB
testcase_19 AC 332 ms
26,404 KB
testcase_20 AC 726 ms
26,404 KB
testcase_21 AC 694 ms
26,404 KB
testcase_22 AC 370 ms
26,284 KB
testcase_23 AC 370 ms
26,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
    }
  }
}
0