Pagini recente » Clasament proba | Cod sursa (job #2930770) | Cod sursa (job #193076) | Cod sursa (job #1123876) | Cod sursa (job #2669086)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 20;
struct trie
{
int pos;
trie *fiu[2];
trie()
{
pos = 0;
memset(fiu, 0, sizeof(fiu));
}
};
trie *T = new trie;
void mask(int x, char *s1, char *s2)
{
int i;
for(i = N ; i >= 0 ; i --)
if(x & (1 << i))
s1[N - i] = '1', s2[N - i] = '0';
else
s1[N - i] = '0', s2[N - i] = '1';
s1[N + 1] = s2[N + 1] = '\n';
}
int p;
void addMask(trie *nod, char *s)
{
if(*s == '\n')
{
nod->pos = p;
return;
}
if(nod->fiu[*s - '0'] == 0)
nod->fiu[*s - '0'] = new trie;
addMask(nod->fiu[*s - '0'], s + 1);
}
int findMask(trie *nod, char *s, int k)
{
if(*s == '\n')
{
p = nod->pos;
return 0;
}
int pos = *s - '0';
if(nod->fiu[pos] == 0)
pos = (1 ^ pos);
return (pos << k) | findMask(nod->fiu[pos], s + 1, k - 1);
}
int main()
{
freopen("xormax.in", "r", stdin);
freopen("xormax.out", "w", stdout);
int n, i, t, x, xormax, y , st , dr;
char s1[22], s2[22];
scanf("%d", &n);
xormax = t = 0;
mask(t, s1, s2);
addMask(T, s1);
p = 0;
for(i = 1 ; i <= n ; i ++)
{
scanf("%d", &x);
t ^= x;
mask(t, s1, s2);
p = i;
addMask(T, s1);
y = findMask(T, s2, 20);
if(t ^ y > xormax)
{
xormax = t ^ y;
st = p;
dr = i;
}
xormax = max(xormax, t ^ y);
}
printf("%d %d %d\n", xormax , st + 1 , dr);
return 0;
}