Cod sursa(job #1858232)

Utilizator TimoteiCopaciu Timotei Timotei Data 27 ianuarie 2017 10:44:13
Problema Arbori de intervale Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.25 kb
#include <iostream>
#include <fstream>
#define nMax 200020

using namespace std;
int n, v[nMax], mij, mx, m, x, type, a, b;
void update(int nod, int st, int dr, int a, int b, int x)
{
    if(a <= st && dr <= b)
        v[nod] = x;
    else {
        mij = (st + dr) / 2;
        if(a <= mij)
          update(2 * nod, st, mij, a, b, x);
        if(b > mij)
            update(2 * nod + 1, mij + 1, dr, a, b, x);
        v[nod] = max(v[2 * nod], v[2 * nod + 1]);
    }
}
int question(int nod, int st, int dr, int a, int b)
{
   if(a <= st && dr <= b)
    return v[nod];
   else {
       mij = (st + dr) / 2;
       if(a <= mij)
        mx = max(mx, question(2 * nod, st, mij, a, b));
       if(b > mij)
        mx = max(mx,question(2 * nod + 1, mij + 1, dr, a, b));
       return mx;
   }
}
void read_and_solve()
{
    ifstream fin("arbint.in");
    ofstream fout("arbint.out");
    fin >> n >> m;
    for(int i = 1; i <= n; ++i){
        fin >> x;
        update(1, 1, n, i, i, x);
    }
    for(int i = 1; i <= n; ++i){
        fin >> type >> a >> b;
        mx = 0;
        if(type) update(1, 1, n, a, a, b);
         else fout << question(1, 1, n, a, b) << '\n';
    }
}
int main()
{
    read_and_solve();
    return 0;
}