Cod sursa(job #2206182)

Utilizator ContDeRacistAliniateEBlat ContDeRacist Data 21 mai 2018 16:19:45
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.13 kb
#include <fstream>

using namespace std;

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

int ans[263009], x, y, val, poz;

void update(int nod, int st, int dr) {
    if (st == dr) {
        ans[nod] = val;
        return;
    }
    int mij((st + dr)>>1);
    if (poz <= mij) {
        update(nod * 2, st, mij);
    }
    else {
        update(nod * 2 + 1, mij + 1, dr);
    }
    ans[nod] = max(ans[nod * 2], ans[nod * 2 + 1]);
}

int scor(int nod, int st, int dr) {
    if (x <= st && dr <= y) {
        return ans[nod];
    }
    int mij((st + dr)>>1);
    int ras(-1);
    if (x <= mij) {
        ras = max(ras, scor(2 * nod, st, mij));
    }
    if (y > mij) {
        ras = max(ras, scor(2 * nod + 1, mij + 1, dr));
    }
    return ras;
}

int main()
{
    int n, k;
    cin >> n >> k;
    for (poz = 1; poz <= n; ++poz) {
        cin >> val;
        update(1, 1, n);
    }
    bool op;
    for (int i = 0; i < k; ++i) {
        cin >> op;
        if (op) {
            cin >> poz >> val;
            update(1, 1, n);
        }
        else {
            cin >> x >> y;
            cout << scor(1, 1, n) << "\n";
        }
    }
    return 0;
}