Pagini recente » Cod sursa (job #3313562) | Cod sursa (job #3318932) | Cod sursa (job #1335845) | Cod sursa (job #3322767) | Cod sursa (job #1939147)
#include <iostream>
#include <fstream>
using namespace std;
/*
poti folosi in loc de 2*nod pe nod<<1
*/
ifstream r("arbint.in");
ofstream w("arbint.out");
int n, m, x, value, pos, a, b;
int aint[4*100000 + 6];
void update(int nod, int st, int dr){
if(st == dr){
aint[nod] = value;
return;
}
int m = (st + dr) / 2;
if(pos <= m) update(2*nod, st, m);
else update(2*nod + 1, m+1, dr);
aint[nod] = max(aint[2*nod], aint[2*nod+1]);
}
void query(int nod, int st, int dr){
if(a <= st && dr <= b){
x = max(x, aint[nod]);
return;
}
int m = (st + dr) / 2;
if(a <= m) query(2*nod, st, m);
if(b > m) query(2*nod+1, m+1, dr);
}
int main()
{
r>>n>>m;
int i;
for(i=1; i<=n; i++){
r>>value;
pos = i;
update(1, 1, n);
}
for(i=1; i<=m; i++){
r>>value>>a>>b;
if(value == 0){
x = -1;
query(1, 1, n);
w<<x<<endl;
}
else{
pos = a;
value = b;
update(1, 1, n);
}
}
return 0;
}