Cod sursa(job #2966115)

Utilizator lucaxsofLuca Sofronie lucaxsof Data 16 ianuarie 2023 19:22:44
Problema Arbori de intervale Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.98 kb
#define _CRT_SECURE_NO_WARNINGS

#include <math.h>
#include <vector>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
//#include <bits/stdc++.h>
using namespace std;

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

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
//8.00->9.15 => 9.30
const int mod = 1e9 + 7;
const int NMAX = 1e5;
const int LIMIT = 1<<14;

int n, m;

int aint[LIMIT + 1], v[NMAX+1];

void read()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> v[i];
}

void build(int p, int st, int dr)
{
    if (st == dr)
    {
        aint[p] = v[st];
        return;
    }
    int mid = (st + dr) / 2;
    int fs = 2 * p, fd = 2 * p + 1;
    build(fs, st, mid);
    build(fd, mid + 1, dr);

    aint[p] = max(aint[fs], aint[fd]);
}

void update(int p, int st, int dr, int pos, int val)
{
    if (st == dr)
    {
        aint[p] = val;
        return;
    }
    int mid = (st + dr) / 2;
    int fs = 2 * p, fd = 2 * p + 1;
    if (pos <= mid)
        update(fs, st, mid, pos, val);
    else
        update(fd, mid + 1, dr, pos, val);
    aint[p] = max(aint[fs], aint[fd]);
}

int query(int p, int st, int dr, int a, int b)
{
    if (a <= st && dr <= b)
        return aint[p];
    int mid = (st + dr) / 2;
    int fs = 2 * p, fd = 2 * p + 1;
    int rezst = INT_MIN, rezdr = INT_MIN;
    if (a <= mid)
        rezst = query(fs, st, mid, a, b);
    if (mid + 1 <= b)
        rezdr = query(fd, mid + 1, dr, a, b);
    return max(rezst, rezdr);
}

void solve()
{
    build(1, 1, n);
    bool x;
    int a, b;
    while (m)
    {
        m--;
        cin >> x >> a >> b;
        if (!x)
            cout << query(1, 1, n, a, b) << '\n';
        else
            update(1, 1, n, a, b);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    read();
    solve();
}