Problem Description
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor of all numbers from this segment was maximal possible. Help him with that.
The xor operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java.
Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.
Output
Print a single integer — the required maximal xor of a segment of consecutive elements.
Examples
Input
5
1 2 1 1 2Output
3
Input
3
1 2 7Output
7
Input
4
4 2 4 8Output
14
Note
In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.
The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
题意:给出一个长度为 n 的正整数序列,求异或和最大的连续子段和
思路:由于异或具有前缀和的性质,因此求前缀和后暴力找最大的区间即可
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int a[N];
int sum[N];
int main() {
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++) {
scanf("%d",&a[i]);
sum[i]=sum[i-1]^a[i];
}
int res=0;
for(int i=1; i<=n; i++)
for(int j=i; j<=n; j++)
res=max(res,sum[j]^sum[i-1]);
printf("%d\n",res);
return 0;
}