Cod sursa(job #2757180)

Utilizator pielevladutPiele Vladut Stefan pielevladut Data 4 iunie 2021 12:02:32
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.25 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("arbint.in");
ofstream fout("arbint.out");

int n, m;
int v[100000];
int aint[400000];
int tip;
int a, b;

void update(int nod, int st, int dr)
{
    if(st == dr)
    {
        aint[nod] = b;
        return ;
    }
    int mijloc = (st + dr) / 2;
    if(a <= mijloc)
    {
        update(2 * nod, st, mijloc);
    }
    else
    {
        update(2 * nod + 1, mijloc + 1, dr);
    }
    aint[nod] = max(aint[2 * nod], aint[2 * nod + 1]);
}

int query(int nod, int st, int dr)
{
    if(st >= a && dr <= b)
    {
        return aint[nod];
    }
    int mijloc = (st + dr) / 2, x = INT_MIN, y = INT_MIN;
    if(a <= mijloc)
    {
        x = query(2 * nod, st, mijloc);
    }
    if(b > mijloc)
    {
        y = query(2 * nod + 1, mijloc + 1, dr);
    }
    return max(x,y);
}

int main()
{
    fin >> n >> m;
    for(int i = 1; i <= n; i ++)
    {
        fin >> v[i];
        a = i;
        b = v[i];
        update(1,1,n);
    }
    while(m--)
    {
        fin >> tip;
        fin >> a >> b;
        if(tip)
        {
            update(1, 1, n);
        }
        else
        {
            fout << query(1,1,n) << '\n';
        }
    }
}