Pagini recente » Cod sursa (job #1461659) | Cod sursa (job #1729819) | Cod sursa (job #239742) | Cod sursa (job #1807797) | Cod sursa (job #3221919)
#include <iostream>
#include <vector>
using namespace std;
vector<int> arbint;
int arbSize;
int query(int a, int b, 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(a, b, 2 * nod, st, mij));
}
if (mij < b) {
aux = max(aux, query(a, b, 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 >> M >> N;
arbSize = 1;
while (arbSize < N) {
arbSize *= 2;
}
arbint.resize(2 * arbSize, 0);
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, a, b;
cin >> op >> a >> b;
if (op == 0) {
cout << query(a, b, 1, 1, arbSize) << '\n';
} else {
update(a, b);
}
}
return 0;
}