Cod sursa(job #2336021)

Utilizator IOI_MDA_003Sebastian Chicu IOI_MDA_003 Data 4 februarie 2019 18:40:31
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.23 kb
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>

using namespace std;

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

const int N_MAX = 100000 + 5;
const int INF = 0x3f3f3f3f;

int arbint[4*N_MAX];

int n, m;

void update(int poz, int nou_poz, int val, int st, int dr){
    if(nou_poz == st && st == dr){
        arbint[poz] = val;
        return;
    }

    int mid = (st + dr) / 2;
    
    if(nou_poz <= mid)
        update(poz*2, nou_poz, val, st, mid);
    else
        update(poz*2+1, nou_poz, val, mid + 1, dr);

    arbint[poz] = max(arbint[poz*2], arbint[poz*2+1]);
}

int query(int poz, int lo, int hi, int st, int dr){ 	
     if(st >= lo and dr <= hi)
        return arbint[poz];
    if(hi < st || lo > dr)
        return -INF;
    int mid = (st + dr) / 2;
    return (max(query(poz*2, lo, hi, st, mid),
               query(poz*2 + 1, lo, hi, mid + 1, dr)));
}

int main(){
    fin >> n >> m;
    for(int i = 1, a; i<=n; ++i){
        fin >> a;
        update(1,i,a,1,n);
    }
    while(m--){
        int a, b, c;
        fin >> a >> b >> c;
        if(a == 1){
            update(1, b, c, 1, n);
        } else
            fout << query(1, b, c, 1, n) << "\n";

    }

    return 0;
}
// român convertit la moldovenism