結果
| 問題 |
No.2265 Xor Range Substring Sum Query
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2023-04-07 15:55:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,333 bytes |
| コンパイル時間 | 2,113 ms |
| コンパイル使用メモリ | 181,600 KB |
| 実行使用メモリ | 256,320 KB |
| 最終ジャッジ日時 | 2024-10-02 18:38:42 |
| 合計ジャッジ時間 | 9,189 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 TLE * 1 -- * 19 |
ソースコード
#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)]);
}
}
}
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(){
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;
vector<int> pos;
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;
A[x] = node(y);
pos.push_back(x);
}
if (t == 2){
int L, R, X;
cin >> L >> R >> X;
R++;
vector<int> pos2 = {L - 1, R};
for (int j : pos){
if (L <= (j ^ X) && (j ^ X) < R){
pos2.push_back(j ^ X);
}
}
sort(pos2.begin(), pos2.end());
pos2.erase(unique(pos2.begin(), pos2.end()), pos2.end());
int cnt2 = pos2.size() - 1;
node ans;
for (int j = 0; j < cnt2; j++){
ans = op(ans, ST.range_fold(pos2[j] + 1, pos2[j + 1], X));
if (j < cnt2 - 1){
ans = op(ans, A[pos2[j + 1] ^ X]);
}
}
cout << ans.x << endl;
}
if (pos.size() == (1 << (n / 2))){
ST = xor_segment_tree<node, op, e>(A);
pos.clear();
}
}
}
SSRS