Pagini recente » Cod sursa (job #2455220) | Cod sursa (job #320117) | Cod sursa (job #164505) | Cod sursa (job #2556570) | Cod sursa (job #1140615)
#include <cstdio>
using namespace std;
struct trie {
int x;
trie *p[2];
trie() {
p[0] = p[1] = NULL;
}
};
trie r;
int n;
int mxv,mxs,mxf;
int next, last;
int xr;
void insert(int pos) {
trie *t = &r;
for (int i=25;i>=0;i--) {
if (((1<<i) bitand xr) != 0) {
if (t->p[1] == NULL) t->p[1] = new trie();
t = t->p[1];
} else {
if (t->p[0] == NULL) t->p[0] = new trie();
t = t->p[0];
}
}
t->x = pos;
}
void check(int fin) {
trie *t = &r;
int xorvalue = 0;
for (int i=25;i>=0;i--) {
int h = ((1<<i) bitand xr) != 0;
if (t->p[1-h] != NULL) {
t = t->p[1-h];
xorvalue = (xorvalue<<1) + 1;
}
else if (t->p[h] != NULL) {
t = t->p[h];
xorvalue = xorvalue<<1;
}
}
if (xorvalue > mxv) {
mxv = xorvalue;
mxs = t->x+1;
mxf = fin;
}
}
int main() {
freopen("xormax.in","r",stdin);
freopen("xormax.out","w",stdout);
scanf("%d",&n);
if (n==0) {
printf("0 1 1\n");
return 0;
}
insert(0);
for (int i=1;i<=n;i++) {
scanf("%d",&next);
xr = xr xor next;
check(i);
insert(i);
}
printf("%d %d %d\n",mxv,mxs,mxf);
return 0;
}