Cod sursa(job #2614401)

Utilizator Misha22Misha S Misha22 Data 11 mai 2020 18:01:35
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.1 kb
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/

#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);

#define in fin
#define out fout

using namespace std;

typedef long long ll;
typedef unsigned int uint;
const int nmax = 300005;
const ll linf = LLONG_MAX;
const ll mod = 1e9+7;
const int inf = INT_MAX;

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

int n, m;
int AINT[4*nmax], V[nmax];

void build(int nod , int l , int r){
    if(l == r)AINT[nod] = V[l];
    if(l >= r)return ;
    int mid = (l+r)/2;
    build(2*nod,l,mid);
    build(2*nod+1,mid+1,r);
    AINT[nod] = max(AINT[2*nod], AINT[2*nod+1]);
}

int query(int nod , int l , int r , int lt , int rt){
    if(l > r || l > rt || r < lt)return 0;
    if(l >= lt && r <= rt)return AINT[nod];
    int mid = (l + r)/2;
    return max(query(2*nod,l,mid,lt,rt),query(2*nod+1,mid+1,r,lt,rt));
}

void update(int nod , int l , int r , int pos , int val){
    if(l > pos || r < pos)return ;
    if(l == r){AINT[nod] = val;return ;}
    int mid = (l+r)/2;
    update(2*nod,l,mid,pos,val);
    update(2*nod+1,mid+1,r,pos,val);
    AINT[nod] = max(AINT[2*nod],AINT[2*nod+1]);
}
int main(){
    in >> n >> m;
    for(int i = 1; i <= n; i++){
        in >> V[i];
    }
    build(1,1,n);
    int type, r, l, pos , val;
    for(int i = 1; i <= m; i++){
        in >> type;
        if(type == 0){
            in >> l >> r;
            out << query(1,1,n,l,r) << '\n';
        }else{
            in >> pos >> val;
            update(1,1,n,pos,val);
        }
    }
}