Pagini recente » Borderou de evaluare (job #2585364) | Borderou de evaluare (job #2752085) | Borderou de evaluare (job #638519) | Borderou de evaluare (job #1731251) | Cod sursa (job #1453701)
#include<iostream>
#include<fstream>
#include<cmath>
using namespace std;
int arbmax[400005],ch[400005],N,M,val,a,b;
void update(int nod, int st, int dr);
int interogare(int nod, int st, int dr);
int main(){
ifstream in("arbint.in");
ofstream out("arbint.out");
in>>N>>M;
int i,c;
for(i=1;i<400000;++i) ch[i]=-1;
for(i=1;i<=N;++i){
in>>val;
a=i, b=i;
update(1,1,N);
}
for(i=1;i<=M;++i){
in>>c;
if(c==1){
in>>a;
b=a;
in>>val;
update(1,1,N);
}
else{
in>>a>>b;
out<<interogare(1,1,N)<<'\n';
}
}
}
void update(int nod, int st, int dr){
if(a<=st && dr<=b) arbmax[nod]=val,ch[nod]=val;
else{
if(ch[nod]>-1) ch[nod*2]=ch[nod*2+1]=ch[nod];
ch[nod]=-1;
int m=(st+dr)/2;
if(a<=m) update(nod*2, st, m);
if(b>m) update(nod*2+1, m+1, dr);
arbmax[nod]=max(arbmax[nod*2], arbmax[nod*2+1]);
}
}
int interogare(int nod, int st, int dr)
{
if(a<=st && dr<=b) {return arbmax[nod];}
else{
int m=(st+dr)/2;
int x=-1,y=-1;
if(a<=m) {if(ch[nod*2]>-1) {x=ch[nod*2];}
else {x=interogare(nod*2, st, m); } }
if(m<b) {if(ch[nod*2+1]>-1) y=ch[nod*2+1];
else y=interogare(nod*2+1, m+1, dr);}
int r=max(x,y);
return r;
}
}