Cod sursa(job #2447675)

Utilizator ezioconnorVlad - Gabriel Iftimescu ezioconnor Data 14 august 2019 11:26:15
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.27 kb
#include <fstream>

using namespace std;

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

int n, m, val, poz, c, a, b, MAX, start, finish;
int v[400066];

inline void update(int nod, int st, int dr)
{
    if (st == dr)
    {
        v[nod] = val;
        return;
    }
    int mid = (st + dr) / 2;
    if (poz <= mid)
        update(2 * nod, st, mid);
    else
        update(2 * nod + 1, mid + 1, dr);
    v[nod] = max(v[2 * nod], v[2 * nod + 1]);
}

inline void query(int nod, int st, int dr)
{
    if (start <= st && dr <= finish)
    {
        MAX = max(MAX, v[nod]);
        return;
    }
    int mid = (st + dr) / 2;
    if (start <= mid)
        query(2 * nod, st, mid);
    if (mid < finish)
        query(2 * nod + 1, mid + 1, dr);
}

int main()
{
    in >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        in >> val;
        poz = i;
        update(1, 1, n);
    }
    while (m--)
    {
        in >> c >> a >> b;
        if (!c)
        {
            MAX = -1;
            start = a;
            finish = b;
            query(1, 1, n);
            out << MAX << '\n';
        }
        else
        {
            poz = a;
            val = b;
            update(1, 1, n);
        }
    }
    return 0;
}