結果

問題 No.2265 Xor Range Substring Sum Query
ユーザー とりゐとりゐ
提出日時 2023-03-12 03:21:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4,902 ms / 5,000 ms
コード長 2,093 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 208,188 KB
実行使用メモリ 66,144 KB
最終ジャッジ日時 2024-05-03 08:04:52
合計ジャッジ時間 47,028 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
44,416 KB
testcase_01 AC 17 ms
44,288 KB
testcase_02 AC 16 ms
44,416 KB
testcase_03 AC 17 ms
44,672 KB
testcase_04 AC 2,818 ms
66,140 KB
testcase_05 AC 2,537 ms
66,008 KB
testcase_06 AC 2,568 ms
66,140 KB
testcase_07 AC 2,660 ms
66,008 KB
testcase_08 AC 2,707 ms
66,140 KB
testcase_09 AC 4,689 ms
66,140 KB
testcase_10 AC 4,683 ms
66,144 KB
testcase_11 AC 4,304 ms
66,140 KB
testcase_12 AC 4,902 ms
66,144 KB
testcase_13 AC 4,495 ms
66,136 KB
testcase_14 AC 210 ms
66,136 KB
testcase_15 AC 184 ms
66,012 KB
testcase_16 AC 346 ms
66,144 KB
testcase_17 AC 319 ms
66,144 KB
testcase_18 AC 342 ms
66,136 KB
testcase_19 AC 346 ms
66,136 KB
testcase_20 AC 476 ms
66,144 KB
testcase_21 AC 500 ms
66,136 KB
testcase_22 AC 1,388 ms
55,040 KB
testcase_23 AC 1,450 ms
54,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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