社区讨论
18pts蒻籍求救
P4735最大异或和参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mhj30kfa
- 此快照首次捕获于
- 2025/11/03 19:53 4 个月前
- 此快照最后确认于
- 2025/11/03 19:53 4 个月前
萌新18pts代码求救!只对了第2和第8个点
CPP#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
using namespace std;
using LL = long long;
LL const N = 3e5 + 5;
LL const LOG = 24;
struct TrieTree {
struct PoLL {
LL son[2];
LL l = INF, r = -INF;
} AC[N * LOG];
LL cnt;
TrieTree() {
cnt = 1;
}
using C_T = LL const&;
void insert(C_T val, C_T id) {
LL x = 1;
for (LL i = LOG; i >= 0; i--) {
bool k = val & (1 << i);
if (!AC[x].son[k])
AC[x].son[k] = ++cnt;
AC[x].l = min(AC[x].l, id);
AC[x].r = max(AC[x].r, id);
x = AC[x].son[k];
}
AC[x].l = min(AC[x].l, id);
AC[x].r = max(AC[x].r, id);
}
LL query(C_T val, C_T l, C_T r) {
LL x = 1, res = 0;
for (LL i = LOG; i >= 0; i--) {
bool k = val & (1 << i);
LL desired = !k;
if (AC[x].son[desired]) {
LL son = AC[x].son[desired];
if (!(AC[son].r < l || AC[son].l > r)) {
res |= (1 << i);
x = son;
continue;
}
}
if (AC[x].son[k]) {
LL son = AC[x].son[k];
if (!(AC[son].r < l || AC[son].l > r)) {
x = son;
continue;
}
}
return res;
}
return res;
}
} Tr;
LL w[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
LL n, m;
cin >> n >> m;
w[0] = 0;
Tr.insert(w[0], 0);
for (LL i = 1; i <= n; i++) {
LL a;
cin >> a;
w[i] = w[i - 1] ^ a;
Tr.insert(w[i], i);
}
while (m--) {
char op;
cin >> op;
if (op == 'A') {
LL x;
cin >> x;
n++;
w[n] = w[n - 1] ^ x;
Tr.insert(w[n], n);
} else {
LL l, r, x;
cin >> l >> r >> x;
LL target = w[n] ^ x;
cout << Tr.query(target, l - 1, r - 1) << '\n';
}
}
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...