Cod sursa(job #1266887)

Utilizator Alexa2001Alexa Tudose Alexa2001 Data 19 noiembrie 2014 11:18:17
Problema Arbori de intervale Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.13 kb
#include <cstdio>

using namespace std;

int x,y,op,poz,v,n,m,a[400003],r,i;

inline int Max(int x,int y)
{
    if(x>y)
        return x;
    return y;
}

void upd(int nod,int st,int dr)
{
    int mj;

    if(st==dr)
    {
        a[nod]=v;
        return;
    }

    mj=(st+dr)/2;

    if(poz<=mj) upd(nod*2,st,mj);
    else upd(nod*2+1,mj+1,dr);

    a[mj]=Max(a[nod*2],a[nod*2+1]);

}

inline void q(int nod,int st,int dr)
{
    int mj;

    if(x<=st && dr<=y)
    {
        r=Max(r,a[nod]);
        return;
    }

    mj=(st+dr)/2;

    if(x<=mj) q(nod*2,st,mj);
    else q(nod*2+1,mj+1,dr);


}


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",&v);
        poz=i;
        upd(1,1,n);

    }

    for(i=1; i<=m; ++i)
    {
        scanf("%d%d%d",&op,&x,&y);

        v=y;
        poz=x;
        r=-1;

        if(op==0)
        {
            q(1,1,n);
            printf("%d\n",r);
        }
        else upd(1,1,n);

    }






    return 0;
}