Cod sursa(job #1799755)

Utilizator r00t_Roman Remus r00t_ Data 6 noiembrie 2016 18:56:14
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include <iostream>
#include <vector>
#include <fstream>
#include <climits>
#include <algorithm>

using namespace std;

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

int v1[1000000],tree[1000000];

void update_tree(int st,int dr, int poz, int val, int nod){
    if(st==dr){
        tree[nod]=val;
    }else {
        int mid=(st+dr)/2;
        if(poz<=mid)
            update_tree(st,mid,poz,val,nod*2);
        if(poz>mid)
            update_tree(mid+1,dr,poz,val,nod*2+1);
        tree[nod]=max(tree[nod*2],tree[nod*2+1]);
    }
}

int max_query(int st,int dr,int qst,int qdr,int nod){
    if(st>=qst && dr<=qdr)
        return tree[nod];
    if(st>qdr || dr<qst)
        return INT_MIN;
    int mid = (st+dr)/2;
    return max(max_query(st,mid,qst,qdr,2*nod),
               max_query(mid+1,dr,qst,qdr,2*nod+1));
}

int main()
{
    int n,m,a,b,t;
    fin>>n>>m;
    for(int i=1;i<=n;i++){
        fin>>a;
        update_tree(1,n,i,a,1);
    }
    for(int i=1;i<=m;i++){
        fin>>t>>a>>b;
        if(t==0)
            fout<<max_query(1,n,a,b,1)<<'\n';
        else
            update_tree(1,n,a,b,1);
    }
    return 0;
}