Cod sursa(job #3125857)

Utilizator Radu_MocanasuMocanasu Radu Radu_Mocanasu Data 4 mai 2023 18:08:51
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.47 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int arb[400500];
int M;
/*void build(int nod, int st, int dr){
    if(st == dr){
        arb[nod] = v[st];
        return;
    }
    int med = (st + dr) / 2;
    build(2 * nod,st, med);
    build(2 * nod + 1, med + 1, dr);
    arb[nod] = max(arb[2 * nod], arb[2 * nod + 1]);
}*/
int l,r,poz,val;
void update(int nod, int st, int dr){
    if(st == dr){
        arb[nod] = val;
        return;
    }
    int med = (st + dr) / 2;
    if(poz <= med)
        update(2 * nod, st, med);
    else
        update(2 * nod + 1, med + 1, dr);
    arb[nod] = max(arb[2 * nod], arb[2 * nod + 1]);
}
void query(int nod, int st, int dr){
    if(st >= l && dr <= r){
        if(arb[nod] > M) M = arb[nod];
        return;
    }
    int med = (st + dr) / 2;
    if(l <= med)
        query(2 * nod,st, med);
    if(med < r)
        query(2 * nod + 1, med + 1, dr);
}
int main()
{
    int n,m,i,j,k,c,x,a,b;
    fin >> n >> m;
    for(i = 1; i <= n; i++){
        fin >> x;
        val = x;
        poz = i;
        update(1,1,n);
    }
    for(i = 1; i <= m; i++){
        fin >> c >> a >> b;
        if(c == 0){
            l = a;
            r = b;
            M = 0;
            query(1,1,n);
            fout << M << "\n";
        }
        else{
            poz = a;
            val = b;
            update(1,1,n);
        }
    }
    return 0;
}