Cod sursa(job #561439)

Utilizator vgabi94Vaduva Gabriel vgabi94 Data 20 martie 2011 14:05:17
Problema Xor Max Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>
#include <queue>
using namespace std;

fstream fin("xormax.in", ios::in);
fstream fout("xormax.out", ios::out);

int main()
{
	struct Max {int start; int stop; int value;} maxim, temp, x;
	int n, len; queue<Max> max, nr;
	fin >> n >> temp.value; temp.start = 1; temp.stop = 1; maxim = temp;
	max.push(temp); nr.push(temp); 
	while(!fin.eof())
	{
		fin >> temp.value; temp.stop++; temp.start++; len = max.size();
		for(int i = 0; i < len; i++)
		{
			x.value = temp.value ^ max.front().value; 
			x.start = max.front().start; x.stop = temp.stop;
			max.push(x); 
			maxim = max.back().value > maxim.value ? max.back() : maxim;
			max.pop();
		}
		nr.push(temp);
		x.value = temp.value ^ nr.front().value; x.start = nr.front().start; x.stop = temp.stop;
		max.push(x);
		maxim = max.back().value > maxim.value ? max.back() : maxim;
		nr.pop();
	}
	fout << maxim.value << " " << maxim.start << " " << maxim.stop;
	return 0;
}