Cod sursa(job #3262943)

Utilizator heheboi6Budiul Alexandru Vasile heheboi6 Data 12 decembrie 2024 12:58:30
Problema Arbori de intervale Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.21 kb
#include <fstream>

using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
int N[400001],T[100001];
void build(int nod, int st, int dr){
    if(st!=dr){
        int mij=(st+dr)/2;
        build(nod*2,st,mij);
        build(nod*2+1,mij+1,dr);
        N[nod]=max(N[nod*2],N[nod*2+1]);
    }
    else{
        N[nod]=T[st];
    }
}
void update(int val, int nod, int st, int dr, int poz){
    if(st!=dr){
        int mij=(st+dr)/2;
        if(poz<=mij){
            update(val,nod*2,st,mij,poz);
        }
        else{
            update(val,nod*2+1,mij+1,dr,poz);
        }
        N[nod]=max(N[nod*2],N[nod*2+1]);
    }
    else{
        N[nod]=val;
    }
}
int query(int nod, int stint, int drint, int st, int dr){
    int mij=(st+dr)/2;
    if(stint<st&&drint>dr){
        return N[nod];
    }
    if(stint<=mij){

    }
}
int main()
{
    int n,i,q,tip,poz,val,st,dr;
    f >> n >> q;
    for(i=1;i<=n;i++){
        f >> T[i];
    }
    build(1,1,n);
    for(i=1;i<=q;i++){
        f >> tip;
        if(tip==1){
            f >> poz >> val;
            update(val,1,1,n,poz);
        }
        else{
            f >> st >> dr;

        }
    }
    return 0;
}