Cod sursa(job #1040602)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 24 noiembrie 2013 18:17:19
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.88 kb
#include <cstdio>
#include <algorithm>

#define Nmax 1<<18
#define INF 0x3f3f3f3f

using namespace std;
int N,M,A,B,x,pos,answer;
char Buffer;

class SegmentTree{
private:
    int range[ Nmax ];
public:
    void Update(const int li,const int lf,const int pz)
    {
        if(li == lf)
        {
            range[ pz ] = x;
            return;
        }
        int m = li+((lf-li)>>1);
        if( pos <= m )   Update(li,m,pz<<1);
        else Update(m+1,lf,(pz<<1)|1);
        range[pz] = max(range[pz<<1],range[(pz<<1)|1]);
    }
    void Querry(const int li,const int lf,const int pz)
    {
        if(A <= li && lf <= B)
        {
            answer = max(answer,range[pz]);
            return;
        }
        int m = li+((lf-li)>>1);
        if(A <= m) Querry(li,m,pz<<1);
        if(B > m) Querry(m+1,lf,(pz<<1)|1);
    }
};

SegmentTree aint;

void scan(int &A,int endline)
{
    A = 0;
    do
    {
        Buffer = fgetc(stdin);
        if('0' <= Buffer && Buffer <='9')
            A = A*10 + Buffer-48;
    }while('0' <= Buffer && Buffer <='9');
    if(endline)
        while(Buffer != '\n')
            Buffer = fgetc(stdin);
}

void Read()
{
    scan(N,0),scan(M,1);
    for(int i = 1; i < N; ++i){
        scan(x,0);
        pos = i;
        aint.Update(1,N,1);
    }
    scan(x,1);
    pos = N;
    aint.Update(1,N,1);
}

void Solve()
{
    int op;
    for(int i = 1; i<= M;++i)
    {
        scan(op,0);
        if(!op)
        {
            answer = -INF;
            scan(A,0),scan(B,1);
            aint.Querry(1,N,1);
            printf("%d\n",answer);
        }
        else
        {
            scan(pos,0),scan(x,1);
            aint.Update(1,N,1);
        }
    }
}

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

    Read();
    Solve();

    return 0;
}