Cod sursa(job #3152517)

Utilizator NutaAlexandruASN49K NutaAlexandru Data 25 septembrie 2023 15:46:30
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.18 kb
#include <bits/stdc++.h>
#define bug(a) std::cerr << "(" << #a << ": " << a << ")\n";
#define all(x) x.begin(),x.end()
#define pb push_back
using i64= int64_t;
const int inf=1e9;
const i64 INF=1e18;
const int mod=998244353;
using namespace std;
int n;
vector<int>aint;
void build()
{
    for(int i=n-1; i ;i--)
    {
        aint[i]=max(aint[i<<1],aint[i<<1|1]);
    }
}
void update(int poz,int val)
{
    poz+=n;
    aint[poz]=val;
    for(poz>>=1; poz ;poz>>=1)
    {
        aint[poz]=max(aint[poz<<1],aint[poz<<1|1]);
    }
}
int query(int l,int r)
{
    int rez=0;
    for(l+=n,r+=n;l<=r;l>>=1,r>>=1)
    {
        rez=max(rez,aint[l++]);
        rez=max(rez,aint[r--]);
    }
    return rez;
}
main()
{
    ifstream in("arbint.in");
    ofstream out("arbint.out");
    ios::sync_with_stdio(false);
    in.tie(0);
    int q;
    in>>n>>q;
    aint.resize(n<<1);
    for(int i=n;i<2*n;i++)
        in>>aint[i];
    build();
    while(q--)
    {
        int cer,a,b;
        in>>cer>>a>>b;
        if(cer==0)
        {
            out<<query(a-1,b-1)<<'\n';
        }
        else
        {
            update(a-1,b);
        }
    }

}