Pagini recente » Cod sursa (job #431096) | preONI 2008 - Runda 1 | preONI 2008 - Runda 4, Clasa a 9-a | Clasament preONI 2007, Runda 2, Clasele 11-12 | Cod sursa (job #408429)
Cod sursa(job #408429)
#include<cstdio>
#define nx 100005
using namespace std;
int arb[nx*4],max,a,b,poz,what;
inline int maxim (int x,int y)
{
if (x>y) return x;
else return y;
}
void update (int nod,int st,int dr)
{
if (st==dr)
arb[nod]=what;
else
{
int mij=(st+dr)/2;
if (poz<=mij)
update(nod*2,st,mij);
else update(nod*2+1,mij+1,dr);
arb[nod]=maxim(arb[nod*2],arb[nod*2+1]);
}
}
void query(int nod,int st,int dr)
{
if (a<=st && b>=dr)
{ if (arb[nod]>max) max=arb[nod]; }
else
{
int mij=(st+dr)/2;
if (a<=mij) query(nod*2,st,mij);
if (b>mij) query(nod*2+1,mij+1,dr);
}
}
int main()
{
freopen ("arbint.in","r",stdin);
freopen ("arbint.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
int i,c;
for (i=1;i<=n;++i)
{
scanf("%d",&what);
poz=i;
update(1,1,n);
}
for (;m;--m)
{
scanf("%d%d%d",&c,&a,&b);
if (c==0)
{
max=-1;
query(1,1,n);
printf("%d\n",max);
}
else
{
what=b;poz=a;
update(1,1,n);
}
}
return 0;
}