Cod sursa(job #2637145)

Utilizator Iustin01Isciuc Iustin - Constantin Iustin01 Data 21 iulie 2020 15:13:51
Problema Arbori de intervale Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.19 kb
#include <bits/stdc++.h>
using namespace std;

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

int n, poz, val, v[400066], x, y, a, b, caz, maxim, m;

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

void query(int nod, int st, int dr){
    if(x <= st && dr <= y){
        if(maxim < v[nod])
            maxim = v[nod];
        return;
    }
    int mij = (st + dr) / 2;
    if(x <= mij)
        query(2 * nod, st , mij);
    else
        if(mij < y)
        query(2 * nod + 1, mij + 1, dr);
}

int main(){
    in>>n>>m;
    for(int i = 1; i <= n; i++){
        poz = i;
        in>>val;
        update(1, 1, n);
    }
    for(int i = 1; i <= m; i++){
        in>>caz >> a>> b;
        if(!caz){
            maxim = -1;
            x = a, y = b;
            query(1, 1, n);
            out<<maxim<<"\n";
        }
        else{
            poz = a, val = b;
            update(1, 1, n);
        }
    }
}