Cod sursa(job #1985259)

Utilizator MaarcellKurt Godel Maarcell Data 27 mai 2017 12:27:24
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

const int maxn=100100;
int N,M,t[2*maxn];

void update(int pos, int val){
    for (t[pos+=N]=val; pos>1; pos>>=1)
        t[pos>>1]=max(t[pos],t[pos^1]);
}

int query(int l, int r){
    int res=0;
    for (l+=N, r+=N; l<=r; l=(l+1)>>1,r=(r-1)>>1){
        if (l&1) res=max(res,t[l]);
        if (!(r&1)) res=max(res,t[r]);
    }
    return res;
}

int main(){
	ifstream fin("arbint.in");
	ofstream fout("arbint.out");
    fin >> N >> M;

    int i,l,r,op;
    for (i=0; i<N; i++){
        int x;
        fin >> x;
        update(i,x);
    }

    while (M--){
        fin >> op >> l >> r;
        if (op==0) fout << query(l-1,r-1) << "\n";
        else update(l-1,r);
    }

    return 0;
}