Cod sursa(job #2031093)

Utilizator al_k_ponyClaudiu Babin al_k_pony Data 2 octombrie 2017 18:37:27
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.33 kb
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

int n,m,x,y,op,t[1 << 19];
const int inf = -1e9;

void upd(int nod,int l,int r,int pos,int val)
{
    if(l == r){
        t[nod] = val;
        return ;
    }
    int mid = l + r >> 1;
    if(pos <= mid) upd(nod << 1,l,mid,pos,val);
    else upd(nod << 1 | 1,mid + 1,r,pos,val);
    t[nod] = max(t[nod << 1],t[nod << 1 | 1]);
}

int qry(int nod,int tl,int tr,int l,int r)
{
    if(l > r) return inf;
    if(tl == l && tr == r) return t[nod];
    int mid = tl + tr >> 1;
    return max(qry(nod << 1,tl,mid,l,min(mid,r)),qry(nod << 1 | 1,mid + 1,tr,max(mid + 1,l),r));
}

int32_t main(){_
    freopen("arbint.in","r",stdin);
    freopen("arbint.out","w",stdout);
    //freopen("input","r",stdin);
    cin >> n >> m;
    for(int i = 1;i <= n;i++)
    {
        cin >> x;
        upd(1,1,n,i,x);
    }
    while(m--)
    {
        cin >> op >> x >> y;
        if(!op) cout << qry(1,1,n,x,y) << '\n';
        else upd(1,1,n,x,y);
    }
}