Cod sursa(job #113425)

Utilizator coderninuHasna Robert coderninu Data 10 decembrie 2007 00:02:19
Problema Xor Max Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <stdio.h>
#define Nmax 100001

long c[Nmax], p, u, max, temp, rezX, rezY, aux;
long n, i;

int main()
{
	freopen("xormax.in", "r", stdin);
	scanf("%ld\n", &n);
	for (i=1; i<=n; i++) scanf("%ld ", &c[i]);

	max=temp=c[1];
	p=u=rezX=rezY=1;
	for (i=2; i<=n; i++)
	{
		aux=temp | c[i];
		if (aux > c[i])
		{
			u++;
			temp=aux;
		}
		else
		{
			p=u=i;
			temp=c[i];
		}
		if (temp>max || (temp==max && u-p<rezY-rezX))
		{
			max=temp;
			rezX=p;
			rezY=u;
		}
	}
	fclose(stdin);
	freopen("xormax.out", "w", stdout);
	printf("%ld %ld %ld", max, rezX, rezY);
	fclose(stdout);
	return 0;
}