Cod sursa(job #2615087)

Utilizator andreiomd1Onut Andrei andreiomd1 Data 13 mai 2020 17:17:29
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.66 kb
#include <fstream>

using namespace std;

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

const int NMAX = 1e5 + 5;

int N, Q;

class SegmentTree
{
    int A[(NMAX << 2)];

public:
    inline void Update (int Node, int a, int b, int pos, int val)
    {
        if(a == b)
        {
            A[Node] = val;

            return;
        }

        int Mid = (a + b) >> 1;

        if(pos <= Mid)
            Update(2 * Node, a, Mid, pos, val);

        if(pos > Mid)
            Update(2 * Node + 1, Mid + 1, b, pos, val);

        A[Node] = max(A[2 * Node], A[2 * Node +1]);

        return;
    }

    inline int Query (int Node, int a, int b, int qa, int qb)
    {
        if(qa <= a && b <= qb)
            return A[Node];

        int Mid = (a + b) >> 1;
        int p_Left = 0, p_Right = 0;

        if(qa <= Mid)
            p_Left = Query(2 * Node, a, Mid, qa, qb);

        if(qb > Mid)
            p_Right = Query(2 * Node + 1, Mid + 1, b, qa, qb);

        return max(p_Left, p_Right);
    }
} AINT;

static inline void Read ()
{
    f.tie(nullptr);

    f >> N >> Q;

    for(int i = 1; i <= N; ++i)
    {
        int X = 0;
        f >> X;

        AINT.Update(1, 1, N, i, X);
    }

    return;
}

static inline void TestCase ()
{
    int Type = 0, a = 0, b = 0;
    f >> Type >> a >> b;

    if(Type == 0)
    {
        g << AINT.Query(1, 1, N, a, b) << '\n';

        return;
    }

    AINT.Update(1, 1, N, a, b);

    return;
}

static inline void Solve ()
{
    while(Q--)
        TestCase();

    return;
}

int main()
{
    Read();

    Solve();

    return 0;
}