Cod sursa(job #1862556)

Utilizator TimoteiCopaciu Timotei Timotei Data 30 ianuarie 2017 01:33:30
Problema Arbori de intervale Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.23 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)
{
    if(st == dr)
        v[nod] = b;
    else {
        mij = (st + dr) / 2;
        if(a <= mij)
          update(2 * nod, st, mij, a, b);
         else
          update(2 * nod + 1, mij + 1, dr, a, b);
        v[nod] = max(v[2 * nod], v[2 * nod + 1]);
    }
}
void question(int nod, int st, int dr, int a, int b)
{
   if(a <= st && dr <= b)
       mx = max(v[nod], mx);
    else {
      int mij = (st + dr) / 2;
      if(a <= mij)
        question(2 * nod, st, mij, a, b);
      if(b > mij)
        question(2 * nod + 1, mij + 1, dr, a, b);
     }
}
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, x);
    }
    for(int i = 1; i <= n; ++i){
        fin >> type >> a >> b;
        if(type)  update(1, 1, n, a, b);
         else {
            mx = -1;
            question(1, 1, n, a, b);
            fout << mx << '\n';
         }
    }
}
int main()
{
    read_and_solve();
    return 0;
}