调不会了,WA了,调不出来,求救,感谢
查看原帖
调不会了,WA了,调不出来,求救,感谢
956071
Xiongzx楼主2023/3/22 20:15
#include <bits/stdc++.h>

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define pre(i, a, b) for(int i = (a); i >= (b); i--)
#define Ede(i, u) for(int i = h[u]; i; i = ne[i])
#define go(i, a) for(auto i : a)
//#define int long long
#define LL long long
#define ULL unsigned long long
#define PII pair<int, int>
#define PIL pair<int, long long>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sf scanf
#define prf printf
#define el putchar('\n')
#define mms(arr, n) memset(arr, n, sizeof(arr))
#define mmc(arr1, arr2) memcpy(arr1, arr2, sizeof(arr2))
const int inf = 0x3f3f3f3f;

template <typename T> inline void rd(T &x){
	x = 0; bool f = true; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') f = false; ch = getchar();}
	while(ch >= '0' && ch <= '9'){ x = (x << 1) + (x << 3) + (ch ^ '0'); ch = getchar();}
	if(!f) x = -x;
}
template <typename T, typename ...Args> inline void rd(T &x, Args &...args){ rd(x); rd(args...);}

using namespace std;

const int N = 6e5 + 10;
int n, m; 
int a[N], s[N];
int cre[25 * N], root[N], idx; 
int trie[25 * N][2], len = 23;

void add(int x, int y, int i){
	cre[x] = i;
	pre(k, len, 0){
		int c = s[i] >> k & 1;
		trie[x][!c] = trie[y][!c];
		trie[x][c] = ++idx;
		x = trie[x][c], y = trie[y][c];
		cre[x] = i; //?
	}
}
int query(int l, int r, int v/*定值*/){
	int p = root[r];
	int res = 0;
	pre(k, len, 0){
		int c = v >> k & 1;
		if(trie[p][!c] >= l){
			res += 1 << k;
			p = trie[p][!c];
		}else p = trie[p][c];
	}
	return res;
}

void init(){
	cre[0] = -1;
	root[0] = ++idx;
	add(root[0], 0, 0);
}
int main(){
	/*
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	*/
	init();
	rd(n, m);
	rep(i, 1, n){
		rd(a[i]);
		s[i] = s[i - 1] ^ a[i];
		root[i] = ++idx;
		add(root[i], root[i - 1], i);
	} 
	char ins[2]; int l, r, x;
	rep(i, 1, m){
		sf("%s", ins);
		if(ins[0] == 'A'){
			rd(a[++n]);
			s[n] = s[n - 1] ^ x;
			root[n] = ++idx;
			add(root[n], root[n - 1], n);
		}else{
			rd(l, r, x);
			int ans = query(l - 1, r - 1, x ^ s[n]);
			prf("%d\n", ans);
		}
	}
	return 0;
}





2023/3/22 20:15
加载中...