Pagini recente » Monitorul de evaluare | Cod sursa (job #1570666) | Cod sursa (job #901469) | Cod sursa (job #2104891) | Cod sursa (job #792153)
Cod sursa(job #792153)
#include<stdio.h>
#include<assert.h>
#include <algorithm>
using namespace std;
#define x first
#define y second
#define BIT 21
struct Trie
{
int val;
Trie *st,*dr;
Trie()
{
st=dr=NULL;
}
};
int n,x,y,sol=-1,a[100100];
Trie r;
void add(int t, int index)
{
int i;
Trie *point=&r;
for(i=BIT;i>=0;--i) {
if(t&(1<<i))
{
if(point->dr==NULL)
point->dr=new Trie;
point=point->dr;
}
else
{
if(point->st==NULL)
point->st=new Trie;
point=point->st;
}
point->val = index;
}
}
pair<int, int> query(int t)
{
Trie *point=&r;
int sol=0, index = -1;
for(int i=BIT;i>=0;--i)
{
sol*=2;
if(t&(1<<i))
{
if(point->st)
{
sol+=1;
point=point->st;
}
else
point=point->dr;
}
else
{
if(point->dr)
{
sol+=1;
point=point->dr;
}
else
point=point->st;
}
index = point->val;
}
return make_pair(sol, index);
}
void read()
{
assert(freopen("xormax.in","r",stdin)!=NULL);
int i;
scanf("%d",&n);
for(i=1;i<=n;++i)
scanf("%d",&a[i]);
}
void solve()
{
int i;
pair<int, int> z;
add(0, 0);
for(i=1;i<=n;++i)
a[i]=a[i-1]^a[i];
for(i=1;i<=n;++i)
{
z=query(a[i]);
if(z.x>sol) {
sol=z.x;
x = z.y;
y = i;
}
add(a[i], i);
}
}
void write()
{
assert(freopen("xormax.out","w",stdout)!=NULL);
printf("%d %d %d", sol, x+1, y);
}
int main()
{
read();
solve();
write();
return 0;
}