Cod sursa(job #3032656)

Utilizator tonealexandruTone Alexandru tonealexandru Data 22 martie 2023 16:08:24
Problema Arbori de intervale Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.24 kb
#include <iostream>
#include <fstream>
#include <algorithm>

void update(int node, int from, int to, int pos, int val)
{
    if(from==to)
    {
        st[node]=val;
        return;
    }
    int mid=(from+to)/2;
    if(pos<mid)
        update(node*2, from, mid, pos, val)
    else
        update(node*2+1, mid+1, to, pas, val)

    st[node]=max(st[node]*2, st[node]*2+1);
}

int query(int node, int from, int to, int qleft, int qright)
{
    int smax=0;
    if(qleft<=from && to<=qright)
        return st[node];

    int mid=(from+to)/2;
    if(qleft<=mid)
    {
        int s=query(node*2, from, mid, qleft, qright);
        smax=max(smax, s);
    }
    if(mid+1<=qright)
    {
        int s=query(node*2+1, mid+1, to, qleft, qright);
        smax=max(smax, s);
    }
    return smax;
}

using namespace std;
int st[400005];
int main()
{
    ifstream cin("arbint.in");
    ofstream cout("arbint.out");
    int n,k,x,op,a,b;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        update(1,1,n,i,x);
    }
    for(int i=0;i<k;i++)
    {
        cin>>op>>a>>b;
        if(op==0)
            cout<<query(1,a,b,1,n);
        else if(op==1)
            update(1,1,n,a,b);
    }

    return 0;
}