Pagini recente » Cod sursa (job #2673169) | Cod sursa (job #1989136) | Cod sursa (job #265025) | Cod sursa (job #329046) | Cod sursa (job #2206182)
#include <fstream>
using namespace std;
ifstream cin("arbint.in");
ofstream cout("arbint.out");
int ans[263009], x, y, val, poz;
void update(int nod, int st, int dr) {
if (st == dr) {
ans[nod] = val;
return;
}
int mij((st + dr)>>1);
if (poz <= mij) {
update(nod * 2, st, mij);
}
else {
update(nod * 2 + 1, mij + 1, dr);
}
ans[nod] = max(ans[nod * 2], ans[nod * 2 + 1]);
}
int scor(int nod, int st, int dr) {
if (x <= st && dr <= y) {
return ans[nod];
}
int mij((st + dr)>>1);
int ras(-1);
if (x <= mij) {
ras = max(ras, scor(2 * nod, st, mij));
}
if (y > mij) {
ras = max(ras, scor(2 * nod + 1, mij + 1, dr));
}
return ras;
}
int main()
{
int n, k;
cin >> n >> k;
for (poz = 1; poz <= n; ++poz) {
cin >> val;
update(1, 1, n);
}
bool op;
for (int i = 0; i < k; ++i) {
cin >> op;
if (op) {
cin >> poz >> val;
update(1, 1, n);
}
else {
cin >> x >> y;
cout << scor(1, 1, n) << "\n";
}
}
return 0;
}