Pagini recente » Cod sursa (job #1284601) | Cod sursa (job #1690296) | Cod sursa (job #2890661) | Cod sursa (job #139807) | Cod sursa (job #1935204)
#include <fstream>
using namespace std;
ifstream in ("arbint.in");
ofstream out ("arbint.out");
int N, maxTree[400070], M, Pos, Value, leftQ, rightQ, maxim, X;
void updateTree (int left, int right, int position) {
if (left == right) {
maxTree[position] = Value;
return;
}
int mid = (left + right)/2;
if (Pos <= mid) updateTree (left, mid, 2*position);
else updateTree (mid+1, right, 2*position+1);
maxTree[position] = max (maxTree[2*position], maxTree[2*position+1]);
}
void Query (int left, int right, int position) {
if (leftQ <= left && rightQ >= right){ ///Total Overlap
if (maxim < maxTree[position]) {
maxim = maxTree[position];
}
return;
}
int mid = (left + right)/2;
if (leftQ <= mid) Query (left, mid, 2*position);
if (rightQ > mid) Query (mid+1, right, 2*position+1);
}
int main()
{
in >> N >> M;
for (int i = 1; i <= N; ++ i) {
in >> X;
Pos = i, Value = X;
updateTree (1, N, 1);
}
for (int i = 1; i <= M; ++ i) {
int query, a, b;
in >> query >> a >> b;
if (query == 1) {
Pos = a;
Value = b;
updateTree (1, N, 1);
}
else {
maxim = -1;
leftQ = a;
rightQ = b;
Query (1, N, 1);
out << maxim << '\n';
}
}
return 0;
}