Pagini recente » Cod sursa (job #1786965) | Cod sursa (job #1349963) | Cod sursa (job #2279174) | Cod sursa (job #707314) | Cod sursa (job #2594467)
#include <bits/stdc++.h>
using namespace std;
const int nmax=100005;
int n,a[nmax],curr,ans,last=1,first=1,tazik;
struct Trie{
int val,app[2],num,index;
Trie(){
val = app[0] = app[1] = num = index = 0;
}
}tz;
vector<Trie>vecc;
int getres(int x){
int indx=0;
for(int i=20;i>=0;i--){
int c = 0;
if(x&(1<<i)) c=0;
else c=1;
if(vecc[indx].app[c] && vecc[vecc[indx].app[c]].val>=1){}
else c = (c^1);
indx=vecc[indx].app[c];
}
int g=(x^vecc[indx].num);
tazik=vecc[indx].index;
return g;
}
void buildtrie(int x,int y){
int indx=0;
vector<int>aux;
for(int i=20;i>=0;i--){
int c=0;
if(x&(1<<i)) c=1;
else c=0;
aux.push_back(indx);
if(vecc[indx].app[c]==0){
vecc[indx].app[c]=vecc.size();
vecc.push_back(tz);
indx=vecc.size()-1;
}
else indx=vecc[indx].app[c];
if(i==0){
vecc[indx].num=x;
vecc[indx].index=y;
}
vecc[indx].val++;
}
}
int main(){
ifstream fin("xormax.in");
ofstream fout("xormax.out");
fin >> n;
vecc.push_back(tz);
buildtrie(0,0);
for(int i=1;i<=n;i++){
fin >> a[i];
curr=(curr^a[i]);
int g=getres(curr);
if(ans<g){
ans=g;
last=i;
first=tazik+1;
}
buildtrie(curr,i);
}
fout << ans << ' ' << first << ' ' << last;
}