結果

問題 No.2265 Xor Range Substring Sum Query
ユーザー SSRSSSRS
提出日時 2023-04-07 15:43:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,021 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 193,400 KB
実行使用メモリ 139,648 KB
最終ジャッジ日時 2024-04-10 16:17:05
合計ジャッジ時間 10,149 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 4 ms
5,376 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
struct node{
  long long x, p2, p11;
  node(): x(0), p2(1), p11(1){
  }
  node(int x): x(x), p2(2), p11(11){
  }
};
node op(node L, node R){
  node ans;
  ans.x = (L.x * R.p11 + L.p2 * R.x) % MOD;
  ans.p2 = L.p2 * R.p2 % MOD;
  ans.p11 = L.p11 * R.p11 % MOD;
  return ans;
}
node e(){
  return node();
}
template <typename T, T (*op)(T, T), T (*e)()>
struct xor_segment_tree{
  int LOG, N;
  vector<vector<T>> ST;
  xor_segment_tree(vector<T> &A){
    N = A.size();
    LOG = __builtin_ctz(N);
    ST = vector<vector<T>>(LOG + 1, vector<T>(N));
    for (int i = 0; i < N; i++){
      ST[0][i] = A[i];
    }
    for (int i = 0; i < LOG; i++){
      for (int j = 0; j < N; j++){
        ST[i + 1][j] = op(ST[i][j], ST[i][j ^ (1 << i)]);
      }
    }
  }
  void update(int p, T x){
    ST[0][p] = x;
    for (int i = 0; i < LOG; i++){
      for (int j = 0; j < (1 << (i + 1)); j++){
        ST[i + 1][p ^ j] = op(ST[i][p ^ j], ST[i][p ^ j ^ (1 << i)]);
      }
    }
  }
  T range_fold(int L, int R, int x){
    T ansL = e(), ansR = e();
    for (int i = 0; i < LOG; i++){
      if (L == R){
        break;
      }
      if ((L >> i & 1) == 1){
        ansL = op(ansL, ST[i][L ^ x]);
        L += 1 << i;
      }
      if ((R >> i & 1) == 1){
        R -= 1 << i;
        ansR = op(ST[i][R ^ x], ansR);
      }
    }
    return op(ansL, ansR);
  }
};
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  string S;
  cin >> S;
  vector<node> A(1 << n);
  for (int i = 0; i < (1 << n); i++){
    A[i] = node(S[i] - '0');
  }
  int Q;
  cin >> Q;
  xor_segment_tree<node, op, e> ST(A);
  for (int i = 0; i < Q; i++){
    int t;
    cin >> t;
    if (t == 1){
      int x, y;
      cin >> x >> y;
      ST.update(x, node(y));
      A[x] = node(y);
    }
    if (t == 2){
      int L, R, X;
      cin >> L >> R >> X;
      R++;
      cout << ST.range_fold(L, R, X).x << endl;
    }
  }
}
0