Cod sursa(job #984067)

Utilizator rebound212Mihnea Savu rebound212 Data 13 august 2013 14:14:29
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.43 kb
#include <cstdio>

using namespace std;
int n,m,i,poz,a,b,x,op,arb[1<<19];
inline void actualizare( int nod, int st, int dr)
{
    int m;
    if(st>=poz && dr<=poz)
    {
        arb[nod]=x;
        return;
    }
    else
    {
        m=(st+dr)>>1;
        if(poz<=m)
        {

            actualizare(nod<<1,st,m);
        }
        else
        {
            actualizare((nod<<1)+1,m+1,dr);
        }
        if (arb[nod<<1]<arb[(nod<<1)+1])
        {
            arb[nod]=arb[(nod<<1)+1];
        }
        else
        {
            arb[nod]=arb[nod<<1];
        }
    }
}
inline int interogare (int nod,int st, int dr)
{
    int m,x1,x2;
    x2=x1=0;
    m=(st+dr)>>1;
    if (a<=st && dr<=b)
    {
        return arb[nod];
    }
    if (a<=m)
    {
        x1=interogare(nod<<1,st,m);
    }
    if (b>m)
    {
        x2=interogare((nod<<1)+1,m+1,dr);
    }
    if (x2>x1)
    {
        x1=x2;
    }
    return x1;
}
int main()
{
    freopen("arbint.in","r",stdin);
    freopen("arbint.out","w",stdout);

    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        poz=i;
        actualizare(1,1,n);
    }
    for(i=1; i<=m; i++)
    {
        scanf("%d %d %d",&op,&a,&b);
        if(op==0) printf("%d\n",interogare(1,1,n));
        else
        {
            poz=a;
            x=b;
            actualizare(1,1,n);
        }
    }
    return 0;
}