天天看點

Luogu P4735 最大異或和

#include <cstdio>
#define

int s[A], ch[A][2], cnt, rt[A], n, m, a, b, c, sum;
void build(int pre, int &k, int val, int pos) {
    k = ++cnt, s[k] = s[pre] + 1;
    if (pos < 0) return; int iw = (val >> pos) & 1;
    ch[k][iw ^ 1] = ch[pre][iw ^ 1];
    build(ch[pre][iw], ch[k][iw], val, pos - 1);
}
int ask(int pre, int k, int val, int pos) {
    if (pos < 0) return 0; int iw = (val >> pos) & 1;
    if (s[ch[k][iw ^ 1]] - s[ch[pre][iw ^ 1]] > 0) return (1 << pos) + ask(ch[pre][iw ^ 1], ch[k][iw ^ 1], val, pos - 1);
    else return ask(ch[pre][iw], ch[k][iw], val, pos - 1);
}

int main(int argc, char const *argv[]) {
    scanf("%d%d", &n, &m); build(rt[0], rt[1], 0, 24); n++;
    for (int i = 2; i <= n; i++) scanf("%d", &a), sum ^= a, build(rt[i - 1], rt[i], sum, 24);
    while (m--) {
        char opt[1]; scanf("%s", opt);
        if (opt[0] == 'A') scanf("%d", &a), sum ^= a, build(rt[n], rt[n + 1], sum, 24), n++;
        else scanf("%d%d%d", &a, &b, &c), printf("%d\n", ask(rt[a - 1], rt[b], c ^ sum, 24));
    }
}