Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Istoria paginii utilizator/costy_ | Statistici Ovidiu Piorescu (ovipio) | Cod sursa (job #1007979)
#include<cstdio>
#include<algorithm>
#define NMAX 100000+5
using namespace std;
struct nod
{
int V,St,Dr;
nod *FS,*FD,*T;
};
nod *root;
nod *point[NMAX];
int N,M,V[NMAX],A,B;
nod* do_tree(nod* T,int L,int R)
{
nod* ret=new nod;
ret->St=L;
ret->Dr=R;
ret->T=T;
if(L==R)
{
ret->V=V[L];
point[L]=ret;
return ret;
}
int M=(L+R)/2;
ret->FS=do_tree(ret,L,M);
ret->FD=do_tree(ret,M+1,R);
ret->V=max(ret->FS->V,ret->FD->V);
return ret;
}
void update(int i,int x)
{
V[i]=x;
point[i]->V=x;
for(nod* q=point[i]->T;q;q=q->T) q->V=max(q->FS->V,q->FD->V);
}
int query(nod* T)
{
int st=(T->St),dr=(T->Dr);
if(A<=st && dr<=B) return (T->V);
if(A>dr || st>B) return 0;
return max(query(T->FS),query(T->FD));
}
int main()
{
int i,a,b,t;
freopen("arbint.in","r",stdin);
freopen("arbint.out","w",stdout);
scanf("%d%d",&N,&M);
for(i=1;i<=N;i++) scanf("%d",&V[i]);
root=do_tree(root,1,N);
for(;M;--M)
{
scanf("%d%d%d",&t,&a,&b);
if(t==1)
{
update(a,b);
continue;
}
A=a; B=b;
printf("%d\n",query(root));
}
return 0;
}