Pagini recente » Cod sursa (job #1894136) | Cod sursa (job #885474) | Cod sursa (job #774520) | Cod sursa (job #354652) | Cod sursa (job #3358023)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("xormax.in");
ofstream fout("xormax.out");
int n;
int a[100005];
int sxor[100005];
struct Trie
{
int cnt{};
Trie *leg[2]{};
};
Trie *T=new Trie();
void Insert(int val)
{
Trie *aux=T;
aux->cnt++;
for(int bit=20; bit>=0; bit--)
{
int b=((val>>bit)&1);
if((aux->leg[b])==NULL)
aux->leg[b]=new Trie();
aux=aux->leg[b];
aux->cnt++;
}
}
int main()
{
fin>>n;
for(int i=1; i<=n; i++)
fin>>a[i];
Insert(0);
int ans=0,l=0,r=0;
for(int i=1; i<=n; i++)
{
sxor[i]=(sxor[i-1]^a[i]);
Insert(sxor[i]);
Trie *aux=T;
int v=0;
for(int bit=20; bit>=0; bit--)
{
int b=((sxor[i]>>bit)&1);
if(aux->leg[1-b])
{
v+=(1<<bit);
aux=aux->leg[1-b];
}
else
{
aux=aux->leg[b];
}
}
if(v>ans)
{
ans=v;
r=i;
}
}
for(int i=0; i<r; i++)
{
if((sxor[i]^sxor[r])==ans)
l=i+1;
}
fout<<ans<<" "<<l<<" "<<r<<"\n";
return 0;
}