Pagini recente » infoarena - comunitate informatica, concursuri de programare | infoarena - comunitate informatica, concursuri de programare | Cod sursa (job #303066) | Cod sursa (job #2891690) | Cod sursa (job #1557445)
#include <bits/stdc++.h>
const int kMaxN = 100000;
using namespace std;
int T[2 * kMaxN];
int main(void) {
ifstream in("arbint.in");
ofstream out("arbint.out");
int N, Q;
in >> N >> Q;
for (int i = 0; i < N; i++) {
in >> T[i + N];
}
for (int i = N - 1; i > 0; i--) {
T[i] = max(T[2 * i], T[2 * i + 1]);
}
while (Q--) {
int opType;
in >> opType;
if (!opType) {
int x, y;
in >> x >> y;
x--; y--;
x += step;
y += step;
int ans = 0;
while (x <= y) {
ans = max(ans, T[x]);
x = (x + 1) / 2;
ans = max(ans, T[y]);
y = (y - 1) / 2;
}
out << ans << '\n';
} else {
int x, key;
in >> x >> key;
x--;
x += step;
T[x] = key;
while (x > 1) {
int y = x / 2;
T[y] = max(T[x], T[x ^ 1]);
x = y;
}
}
}
in.close();
out.close();
return 0;
}