Cod sursa(job #2547707)

Utilizator XsoundCristian-Ioan Roman Xsound Data 15 februarie 2020 16:44:47
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.55 kb
#include <bits/stdc++.h>
#define Nmax 400005
using namespace std;
ifstream fin ( "arbint.in" );
ofstream fout ( "arbint.out" );

vector < int > ST;

void Read ( );
void Fac_ST ( int st, int dr, int pos );

int Search_ST ( int st, int dr, int pos );
void Update_ST  ( int st, int dr, int pos );

int n, m, vpos, val, x, y;

int main ( )
{
    Read ( );
}

int Search_ST ( int st, int dr, int pos )
{
    if ( st >= x && y >= dr )
        return ST[pos];

    int mij = ( st + dr ) / 2;
    int max1 = 0, max2 = 0;

    if ( x <= mij )
        max1 = Search_ST ( st, mij, pos*2 );

    if ( y >= mij+1 )
        max2 = Search_ST ( mij+1, dr, pos*2+1 );

    return max ( max1, max2 );
}

void Update_ST ( int st, int dr, int pos )
{
    if ( st == dr )
        ST[pos] = val;

    else
    {
        int mij = ( st + dr ) / 2;

        if ( vpos <= mij )
            Update_ST ( st, mij, pos*2 );
        else
            Update_ST ( mij+1, dr, (pos*2)+1 );

        ST[pos] = max ( ST[pos*2], ST[(pos*2)+1] );
    }
    return ;
}

void Read ( )
{

    int task;

    fin >> n >> m;
    ST.reserve( 4*(n+1) );

    for ( int i = 1; i <= n; i++ )
    {
        fin >> val;

        vpos = i;

        Update_ST ( 1, n, 1 );
    }

    for ( int i = 1; i <= m; i++ )
    {
        fin >> task >> x >> y;

        if ( task == 0 )
            fout << Search_ST ( 1, n, 1 ) << '\n';
        else
        {
            vpos = x;
            val = y;
            Update_ST ( 1, n, 1 );
        }
    }
}