mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:28:48 +00:00
parent
4e3388bae2
commit
3f5ea197e0
87
LibreOJ/6850/6850.cpp
Normal file
87
LibreOJ/6850/6850.cpp
Normal 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
BIN
LibreOJ/6850/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user