Cod sursa(job #964140)
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
int n, m, x, y, sol, vv[(1<<18)+13];
void up(int nd, int st, int dr){
if(st==dr){
vv[nd]=y;
return;
} else {
int md=(st+dr)/2;
if(x<=md)up(2*nd,st,md); else
up(2*nd+1,md+1,dr);
vv[nd]=max(vv[2*nd], vv[2*nd+1]);
}
}
void que(int nd,int st,int dr){
if(x<=st&&dr<=y){
sol=max(sol,vv[nd]);
return;
} else {
int md=(st+dr)/2;
if(x<=md)que(2*nd,st,md);
if(y>md)que(2*nd+1,md+1,dr);
}
}
int main(){
int op;
f >> n >> m;
for(int i=0;i<n;i++){
x=i+1;
f >> y;
up(1,1,n);
}
for(int i=0;i<m;i++){
f >> op >> x >> y;
if(op)up(1,1,n); else{
sol=0;
que(1,1,n);
g << sol << "\n";
}
//for(int j=0;j<2*n;j++) cout << vv[j] << " " ;
//cout << "\n";
}
return 0;
}