Pagini recente » Monitorul de evaluare | Borderou de evaluare (job #1917928) | Cod sursa (job #977543) | Cod sursa (job #833907) | Cod sursa (job #3354072)
#include <algorithm>
#include <fstream>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
const int nmax= 100000;
const int pmax= 262144;
int tree[pmax+1];
int query(int a, int b, int x, int x_start, int x_end) {
if ( b<x_start || a>x_end ) {
return 0;
} else if ( a<=x_start && x_end<=b ) {
return tree[x];
} else {
return max( query(a, b, x<<1, x_start, (x_start+x_end-1)>>1),
query(a, b, ((x<<1)+1), ((x_start+x_end-1)>>1)+1, x_end) );
}
}
void update(int a, int b) {
tree[a]= b;
for ( a>>= 1; a>0; a>>= 1 ) {
tree[a]= max(tree[a<<1], tree[(a<<1)+1]);
}
}
int main() {
int n, m, p= 1;
fin>>n>>m;
while ( p<n ) {
p<<= 1;
}
for ( int i= 0; i<n; ++i ) {
fin>>tree[p+i];
}
for ( int i= p-1; i>0; --i ) {
tree[i]= max(tree[i<<1], tree[(i<<1)+1]);
}
for ( int i= 0, x, a, b; i<m; ++i ) {
fin>>x>>a>>b;
if ( x==0 ) {
fout<<query(a+p-1, b+p-1, 1, p, p*2-1)<<"\n";
} else {
update(p+a-1, b);
}
}
return 0;
}