Cod sursa(job #1200728)
Utilizator | Data | 23 iunie 2014 14:11:22 | |
---|---|---|---|
Problema | Arbori de intervale | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 1.41 kb |
#include<fstream>
using namespace std;
ifstream cin("arbint.in");
ofstream cout("arbint.out");
int n,m,i,A[500013],op,a,b,maxim,val,aux;
void update(int nod,int st,int dr)
{
if (st==dr) A[nod]=val;
else {
int mij =(st+dr)/2;
if (aux<=mij) update(nod*2,st,mij);
else update(nod*2+1,mij+1,dr);
A[nod]=max(A[2*nod],A[2*nod+1]);
}
}
void query (int nod,int st ,int dr ,int poz_st,int poz_dr)
{
if (poz_st<=st && poz_dr>=dr) maxim=max(maxim,A[nod]);
else {
int mij=(st+dr) /2;
if (poz_st<=mij) query (2*nod,st,mij,poz_st,poz_dr);
if (poz_dr>mij) query (2*nod+1,mij+1,dr,poz_st,poz_dr);
}
}
int main()
{
cin>>n>>m;
for (i=1;i<=n;++i) {
cin>>val;
aux=i;
update(1,1,n);
}
while (m--){
cin>>op>>a>>b;
if (op==0) {
maxim=0;
query(1,1,n,a,b);
cout<<maxim<<"\n";
}
if (op==1) {
aux=a;
update(1,1,n);
}
}
return 0 ;
}