记录编号 358453 评测结果 AAAAAAAAAA
题目名称 [国家集训队2009]异或序列 最终得分 100
用户昵称 GravatarFmuckss 是否通过 通过
代码语言 C++ 运行时间 0.050 s
提交时间 2016-12-16 18:40:06 内存使用 25.11 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 1e5 + 10;


#define is_num(x) (x <= '9' and x >= '0')
inline int get_num() {
	char tmp = getchar();
	int res = 0;
	
	while (not is_num(tmp)) tmp = getchar();
	while (    is_num(tmp)) {
		res = (res << 3) + (res << 1) + tmp - '0';
		tmp = getchar();
	}
	
	return res;
}


inline int get_size(int tar) {
	int top = 0;
	for (int i = 0; i <= 30; i++) {
		if (tar & (1 << i)) top = i;
	}
	return top + 1;
}


int n;
int v[MAXN];
int top_len;
int ncnt;
int son[MAXN * 32][2];


int query(int tar) {
	int now = 0, ans = 0;
	for (int i = top_len - 1; i >= 0; i--) {
		int ne = not ((bool)(tar & (1 << i)));
		if (son[now][ne]) ans += (1 << i), now = son[now][ne];
		else now = son[now][not ne];
	}
	return ans;
}

void insert(int tar) {
	int now = 0;
	for (int i = top_len - 1; i >= 0; i--) {
		int ne = (bool)(tar & (1 << i));
		if (not son[now][ne]) son[now][ne] = ++ncnt;
		now = son[now][ne]; 
	}
}


void read() {
	n = get_num();
	int tmp = 0;
	for (int i = 1; i <= n; i++) {
		v[i] = get_num();
		tmp |= v[i];
	}
	top_len = get_size(tmp);
} 


void solve() {
	int now = 0, ans = 0;
	insert(0);
	for (int i = 1; i <= n; i++) {
		now ^= v[i];
		ans = max(ans, query(now));
		insert(now);
	}
	printf("%d\n", ans);
}


int main() {
	freopen("cow_xor.in", "r", stdin);
	freopen("cow_xor.out", "w", stdout); 
	read();
	solve();
	return 0;
}