传送门
题意
分析
水群看到的题,woc贼妙
我们都知道,要表示一个区间的异或和的话,可以用前缀和处理,那么这里有两个,要怎么处理呢
我们用
a
a
a数组表示原序列的异或和前缀和,
b
b
b表示原序列 + 的异或和前缀和,我们从0 - n开始循环,不停的把
a
[
n
]
a
[
i
]
⊕
b
[
i
]
a[n] ^ a[i] \oplus b[i]
a[n]a[i]⊕b[i]插入,也就是插入了类似于
a
a
a
a
b
b
b
b
aaaabbbb
aaaabbbb的形式,然后对
a
[
i
]
o
p
l
u
s
b
[
i
]
a[i] oplus b[i]
a[i]oplusb[i]求最大异或对,就可以消除前面一段的
a
a
a,用
b
b
b替换
代码
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 3e5 + 10;
const ll mod = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
int gcd(int a, int b) {return (b > 0) ? gcd(b, a % b) : a;}
int son[N][2],idx;
int a[N],b[N];
int n;
void insert(int x){
int p = 0;
for(int i = 30;i >= 0;i--){
int &s = son[p][x >> i & 1];
if(!s) s = ++idx;
p = s;
}
}
int query(int x){
int p = 0,ans = 0;
for(int i = 30;i >= 0;i--){
int s = x >> i & 1;
if(son[p][!s]){
ans += 1 << i;
p = son[p][!s];
}
else p = son[p][s];
}
return ans;
}
int main() {
read(n);
for(int i = 1;i <= n;i++) read(a[i]),b[i] = a[i] + 1;
for(int i = 2;i <= n;i++) a[i] ^= a[i - 1],b[i] ^= b[i - 1];
int ans = 0;
for(int i = 0;i <= n;i++){
int x = a[n] ^ a[i] ^ b[i];
insert(x);
ans = max(ans,query(a[i] ^ b[i]));
}
di(ans);
return 0;
}