Pagini recente » Diferente pentru utilizator/mister_ady intre reviziile 1 si 15 | Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #3146053)
#include <fstream>
#include<vector>
using namespace std;
ifstream cin("xormax.in");
ofstream cout("xormax.out");
struct Pos {
int index, value;
};
vector<pair<Pos, Pos>> dp;
vector<int> v;
int main()
{
int i, j, n, nr,v1,v2,k,maxx,st,end;
cin >> n;
for (i = 0; i < n; i++) {
cin >> nr;
v.push_back(nr);
}
dp.push_back({ { 0,v[0] }, { 0,v[0] } });
maxx = v[0];
st=end = 0;
for (i = 1; i < n; i++) {
pair<Pos, Pos> p;
v1 = dp[i - 1].first.value ^ v[i];
v2 = dp[i - 1].second.value ^ v[i];
if (v1 > v2) {
p.first.value = v1;
p.first.index = dp[i - 1].first.index;
}
else {
p.first.value = v2;
p.first.index = dp[i - 1].second.index;
}
p.second.index = i;
p.second.value = v[i];
if (maxx < p.first.value) {
maxx = p.first.value;
st = p.first.index;
end = i;
if (maxx == p.second.value) {
st = p.second.index;
}
}
if (maxx < p.second.value) {
maxx = p.second.value;
st = p.second.index;
end = i;
}
dp.push_back(p);
}
cout << maxx << " " << st+1<< " " << end+1;
return 0;
}