Pagini recente » Cod sursa (job #241956) | Cod sursa (job #963550) | Cod sursa (job #541544) | Cod sursa (job #614749) | Cod sursa (job #2018498)
#include <bits/stdc++.h>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
int N, M, a[200005], type, x, y;
void build() {
for (int i = N - 1; i > 0; --i) {
a[i] = max(a[i << 1], a[(i << 1) + 1]);
}
}
void update(int pos, int val) {
for (a[pos += N] = val; pos > 1; pos >>= 1) {
a[pos >> 1] = max(a[pos], a[pos ^ 1]);
}
}
// query on interval [l, r)
int query(int l, int r) {
int res = 0;
for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
if (l & 1) {
res = max(res, a[l++]);
}
if (r & 1) {
res = max(res, a[--r]);
}
}
return res;
}
int main() {
f >> N >> M;
for (int i = 0; i < N; ++i) {
f >> a[i + N];
}
build();
for (int i = 0; i < M; ++i) {
f >> type >> x >> y;
--x;
if (type) {
update(x, y);
} else {
g << query(x, y) << '\n';
}
}
return 0;
}