Mai intai trebuie sa te autentifici.
Cod sursa(job #1022637)
| Utilizator | Data | 5 noiembrie 2013 20:16:40 | |
|---|---|---|---|
| Problema | Schi | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.17 kb |
#include<stdio.h>
int n,m,v[4000102],poz,val,st,sf;
inline int max(int a,int b)
{
return a>=b?a:b;
}
inline void update(int l,int r,int x)
{
if(l==r)
{
v[x]=val;
return;
}
int med=(l+r)/2,p=x+x;
if(poz<=med)
update(l,med,p);
else
update(med+1,r,p+1);
v[x]=max(v[p],v[p+1]);
}
inline void query(int l,int r,int x)
{
if(st<=l && r<=sf)
{
val=max(val,v[x]);
return;
}
int med=(l+r)/2,p=x+x;
if(st<=med)
query(l,med,p);
if(med<sf)
query(med+1,r,p+1);
}
int main()
{
freopen("arbint.in","r",stdin);
freopen("arbint.out","w",stdout);
int i,x,t,a,b;
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)
{
scanf("%d",&x);
poz=i;
val=x;
update(1,n,1);
}
while(m--)
{
scanf("%d",&t);
if(t==0)
{
scanf("%d%d",&st,&sf);
val=-1;
query(1,n,1);
printf("%d\n",val);
}
else
{
scanf("%d%d",&poz,&val);
update(1,n,1);
}
}
return 0;
}
