Pagini recente » Cod sursa (job #1983862) | Cod sursa (job #2197711) | Cod sursa (job #2033671) | Cod sursa (job #1209684) | Cod sursa (job #1241323)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
const int NMAX = 100000 + 1;
int n, Q, valoare, poz;
int a, b, sol;
int arb[4 * NMAX];
void update(int nod, int st, int dr) {
if (st == dr) arb[nod] = valoare;
else {
int m = (st + dr) / 2;
if (poz <= m) update(2 * nod, st, m);
else update(2 * nod + 1, m + 1, dr);
arb[nod] = max(arb[2 * nod], arb[2 * nod + 1]);
}
}
int query(int nod, int st, int dr) {
if (st == dr) sol = max(arb[nod], sol);
else {
int m = (st + dr) / 2;
if (a <= m) query(2 * nod, st, m);
if (m < b) query(2 * nod + 1, m + 1, dr);
}
}
void citeste() {
f >> n >> Q;
for (int i = 1; i <= n; i++) {
f >> valoare;
poz = i;
update(1, 1, n);
}
}
void rezolva() {
int q;
while (Q--) {
f >> q >> a >> b;
if (q == 0) {
sol = -1;
query(1, 1, n);
g << sol << '\n';
}
else {
poz = a; valoare = b;
update(1, 1, n);
}
}
}
int main() {
citeste();
rezolva();
return 0;
}