Pagini recente » Cod sursa (job #2782420) | Cod sursa (job #357993) | Cod sursa (job #2413983) | Cod sursa (job #2357722) | Cod sursa (job #2708960)
#include <iostream>
#include <fstream>
#define MAXN 100001
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int maxnod[MAXN*4+66],n,m;
int in,out,poz,val,rez;
inline int mx(int a,int b){
if(a>b) return a;
return b;
}
void act(int nod,int st,int dr){
if(st==dr){
maxnod[nod]=val;
return;
}
int mij=(st+dr)/2;
if(poz<=mij) act(nod*2,st,mij);
else act(nod*2+1,mij+1,dr);
maxnod[nod]=mx(maxnod[nod*2],maxnod[nod*2+1]);
}
void ask(int nod,int st,int dr){
if(in<=st and dr<=out){
if(rez<maxnod[nod]) rez=maxnod[nod];
return;
}
int mij=(st+dr)/2;
if(in<=mij) ask(nod*2,st,mij);
if(mij<out) ask(nod*2+1,mij+1,dr);
}
int main(){
fin>>n>>m;
for(int i=1;i<=n;i++){
int x;
fin>>x;
poz=i,val=x;
act(1,1,n);
}
for(int i=1;i<=m;i++){
bool op;
fin>>op;
if(op==0){
fin>>in>>out;
rez=-1;
ask(1,1,n);
fout<<rez<<'\n';
}
else{
fin>>poz>>val;
act(1,1,n);
}
}
return 0;
}