0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 17:48:48 +00:00

#6850. 最大异或和

https://loj.ac/s/1661199
This commit is contained in:
Baoshuo Ren 2022-12-30 22:31:48 +08:00
parent 4e3388bae2
commit 3f5ea197e0
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 147 additions and 0 deletions

87
LibreOJ/6850/6850.cpp Normal file
View File

@ -0,0 +1,87 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 6e5 + 5;
int n, m, sum;
int cnt, tot, root[N], lst[N], tr[N << 5][2], siz[N << 5];
void insert(int val) {
root[++tot] = ++cnt;
int l = root[tot - 1], r = root[tot];
for (int i = 30; i >= 0; i--) {
bool x = val >> i & 1;
tr[r][x ^ 1] = tr[l][x ^ 1];
tr[r][x] = ++cnt;
l = tr[l][x];
r = tr[r][x];
siz[r] = siz[l] + 1;
}
lst[tot] = cnt;
}
int query(int l, int r, int val) {
int res = 0;
l = root[l], r = root[r];
for (int i = 30; i >= 0; i--) {
bool x = val >> i & 1;
if (siz[tr[r][x ^ 1]] > siz[tr[l][x ^ 1]]) {
res |= 1 << i;
x = x ^ 1;
}
l = tr[l][x];
r = tr[r][x];
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
insert(0);
for (int i = 1, x; i <= n; i++) {
cin >> x;
insert(sum ^= x);
}
while (m--) {
char op;
cin >> op;
if (op == 'A') {
int x;
cin >> x;
insert(sum ^= x);
} else { // op == 'Q'
int l, r, x;
cin >> l >> r >> x;
cout << query(l - 1, r, x ^ sum) << endl;
}
}
return 0;
}

BIN
LibreOJ/6850/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6850/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.