求助 45 pts
查看原帖
求助 45 pts
406941
Register_int-std=c++14楼主2022/10/8 18:11

rt.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 1e6 + 10;
const int MAXM = 2e7 + 10;

int rt[MAXN];
int val[MAXM], ch[MAXM][2], tot;

inline 
int add(int pre) {
	ch[++tot][0] = ch[pre][0], ch[tot][1] = ch[pre][1];
	val[tot] = val[pre];
	return tot;
}

inline 
void insert(int &p, int pre, int x) {
	int k = p = add(pre); val[k]++;
	for (int i = 23, t; ~i; i--) {
		t = x >> i & 1;
		ch[k][t] = add(ch[pre][t]), val[ch[k][t]]++;
		k = ch[k][t], pre = ch[pre][t]; 
	}
}

inline 
int query(int p, int pre, int x) {
	int res = 0;
	for (int i = 23, t; ~i; i--) {
		t = x >> i & 1;
		if (val[ch[p][!t]] > val[ch[pre][!t]]) res += 1 << i, p = ch[p][!t], pre = ch[pre][!t];
		else p = ch[p][t], pre = ch[pre][t];
	}
	return res;
}

int n, m, a[MAXN];

char opt[5];

int l, r, x;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]); insert(rt[0], 0, 0);
	for (int i = 1; i <= n; i++) a[i] ^= a[i - 1], insert(rt[i], rt[i - 1], a[i]);
	while (m--) {
		scanf("%s", opt);
		if (*opt == 'A') scanf("%d", &x), a[++n] = a[n - 1] ^ x, insert(rt[n], rt[n - 1], a[n]);
		else scanf("%d%d%d", &l, &r, &x), printf("%d\n", query(rt[r - 1], l < 2 ? 0 : rt[l - 2], a[n] ^ x));
	}
}
2022/10/8 18:11
加载中...