Cod sursa(job #1316897)

Utilizator Vele_GeorgeVele George Vele_George Data 14 ianuarie 2015 11:53:36
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <fstream>
#define nmax 100005
using namespace std;

ifstream f("arbint.in");
ofstream g("arbint.out");

int T[4*nmax],n,m,x,y,sol,act;

void Update(int nod, int st, int dr)
{
    if (st==dr) T[nod]=y;
    else
    {
        int mid=(st+dr)/2;
        if (x<=mid) Update(2*nod, st, mid); //st
               else Update(2*nod+1, mid+1, dr); //dr
        T[nod]=max(T[2*nod],T[2*nod+1]);
    }
}
void Search(int nod, int st, int dr)
{
    if(x<=st && dr <=y) sol=max(sol,T[nod]);
    else
    {
        int mid=(st+dr)/2;
        if (x<=mid) Search(2*nod, st , mid); //st
        if (mid <y) Search(2*nod+1, mid+1, dr); //dr
    }
}


int main()
{
    f >> n >> m;

    for(int i=1; i<=n; i++)
    {
        f >> y;
        x = i;
        Update(1,1,n);
    }


    for(int i=1; i<=m; i++)
    {
        f >> act >> x >> y;
        if (act==0)
        {
            sol=0;
            Search(1,1,n);
            g << sol << "\n";
        }else{
            Update(1,1,n);
        }
    }

    return 0;
}