Cod sursa(job #69661)

Utilizator M@2Te4iMatei Misarca M@2Te4i Data 3 iulie 2007 20:27:57
Problema Xor Max Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<stdio.h>
#define v 100005

long long a[v],w,start,stop,max;
long n;

void citire()
{
freopen("xormax.in","r",stdin);
scanf("%lld", &n);
for (int i=0; i<n; i++)
    scanf("%lld", &a[i]);
fclose(stdin);
}

void xormax()
{
w=a[0];
start=1;
max=w;
stop=1;
long long inc=1,e;
for (long i=1; i<n; i++)
    {
    e=a[i]^w;
    if (e>a[i])
       {
       w^=a[i];
       }
       else {
	    w=a[i];
	    inc=i+1;
	    }
    if (w>max)
       {
       start=inc;
       stop=i+1;
       max=w;
       }
    }
}

void printare()
{
freopen("xormax.out","w",stdout);
printf("%lld %lld %lld",max,start,stop);
fclose(stdout);
}

int main()
{
citire();
xormax();
printare();
return 0;    
}