Pagini recente » Cod sursa (job #2718949) | Cod sursa (job #998086) | Cod sursa (job #797076) | Cod sursa (job #2029486) | Cod sursa (job #3221921)
#include <iostream>
using namespace std;
int arbSize, arbint[(1 << 18)];
int a, b;
int query(int nod, int st, int dr) {
if (a <= st && dr <= b) {
return arbint[nod];
}
int mij = (st + dr) / 2;
int aux = 0;
if (a <= mij) {
aux = max(aux, query(2 * nod, st, mij));
}
if (mij < b) {
aux = max(aux, query(2 * nod + 1, mij + 1, dr));
}
return aux;
}
void update(int poz, int val) {
int i = arbSize + poz - 1;
arbint[i] = val;
i /= 2;
while (i > 0) {
arbint[i] = max(arbint[2 * i], arbint[2 * i + 1]);
i /= 2;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
freopen("arbint.in", "r", stdin);
freopen("arbint.out", "w", stdout);
int N, M;
cin >> N >> M;
arbSize = 1;
while (arbSize < N) {
arbSize *= 2;
}
for (int i = arbSize; i < arbSize + N; i++) {
cin >>arbint[i];
}
for (int i = arbSize - 1; i > 0; i--) {
arbint[i] = max(arbint[2 * i], arbint[2 * i + 1]);
}
for (int i = 0; i < M; i++) {
int op;
cin >> op >> a >> b;
if (op == 0) {
cout << query(1, 1, arbSize) << '\n';
} else {
update(a, b);
}
}
return 0;
}