Cod sursa(job #356941)

Utilizator jupanubv92Popescu Marius jupanubv92 Data 17 octombrie 2009 17:52:24
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.25 kb
#include<stdio.h>
#define Nmx 100001

int n,m;
int U[4*Nmx+70],A,val,B,max,pos;

int MAX(int a,int b)
{
    if(U[a]>U[b]) return U[a];
    else return U[b];
}

void update(int nod,int st,int dr)
{
    if(st==dr)
    {
        U[nod]=val;
        return ;
    }
    int mij=(st+dr)/2;
    if(pos<=mij)  update(2*nod,st,mij);
    if(pos>mij) update(2*nod+1,mij+1,dr);
    U[nod]=MAX(nod*2,nod*2+1);
}

void maxx(int nod,int st,int dr)
{
    if(st>=A&&dr<=B)
    {
        if(U[nod]>max) max=U[nod];
        return ;
    }
    int mij=(st+dr)/2;
    if(A<=mij) maxx(nod*2,st,mij);
    if(mij<B) maxx(nod*2+1,mij+1,dr);
}

void citire()
{
    int c,x,y;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
        {
            scanf("%d",&x);
            val=x;pos=i;
            update(1,1,n);
        }
    for(int i=1;i<=m;++i)
     {
        scanf("%d%d%d",&c,&x,&y);
        max=-1;
        if(c==0)
          {
             A=x;B=y;
             maxx(1,1,n);
             printf("%d\n",max);
          }
        else {
         pos=x;val=y;
         update(1,1,n);
        }
     }
}

int main()
{
    freopen("arbint.in","r",stdin);
    freopen("arbint.out","w",stdout);
    citire();
    return 0;
}