Cod sursa(job #1766516)

Utilizator PlayHPPet Rescue PlayHP Data 27 septembrie 2016 23:52:40
Problema Arbori de intervale Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 2.69 kb
#include <cstdio>
#include <cctype>

#define BUF_SIZE 1<<17
#define MAXN 100000
#define MAXP 265000

int v[MAXN+1], aint[MAXP];
int n, left, right, poz, ans;

int pos=BUF_SIZE;
char buf[BUF_SIZE];
FILE *fin;

inline char nextch(){
    if(pos==BUF_SIZE) fread(buf, BUF_SIZE, 1, fin), pos=0;
    return buf[pos++];
}

inline int read(){
    int x=0;
    /*char ch=nextch();
    while(!isdigit(ch)) ch=nextch();
    while(isdigit(ch)){
        x=10*x+ch-'0';
        ch=nextch();
    }*/
    fscanf(fin, "%d", &x);
    return x;
}

inline int max2(int a, int b){
    if(a>b) return a;
    else return b;
}

void dfs(int p, int st, int dr){
    if(st==dr) aint[p]=v[st];
    else{
        int m=(st+dr)/2;
        dfs(2*p, st, m);
        dfs(2*p+1, m+1, dr);
        aint[p]=max2(aint[2*p], aint[2*p+1]);
    }
}

inline void update(){
    int p=1, st=1, dr=n, m;
    while(st<dr){
        m=(st+dr)/2;
        if(poz<=m) dr=m, p*=2;
        else st=m+1, p=2*p+1;
    }
    aint[p]=v[st];
    p/=2;
    while(p){
        aint[p]=max2(aint[2*p], aint[2*p+1]);
        p/=2;
    }
}

inline void query(){
    if(left==right) ans=v[left];
    else{
        int p=1, st=1, dr=n, m=(n+1)/2, cp, cst, cdr;
        while((right<=m)||(m+1<=left)){
            if(right<=m) dr=m, p*=2;
            else st=m+1, p=2*p+1;
            m=(st+dr)/2;
        }
        cp=p;
        cst=st;
        cdr=dr;
        dr=m;
        p*=2;
        while(st<left){
            m=(st+dr)/2;
            if(m+1<=left) st=m+1, p=2*p+1;
            else{
                ans=max2(ans, aint[2*p+1]);
                dr=m;
                p*=2;
            }
        }
        ans=max2(ans, aint[p]);
        st=cst;
        dr=cdr;
        p=cp;
        m=(st+dr)/2;
        st=m+1;
        p=2*p+1;
        while(right<dr){
            m=(st+dr)/2;
            if(right<=m) dr=m, p*=2;
            else{
                ans=max2(ans, aint[2*p]);
                st=m+1;
                p=2*p+1;
            }
        }
        ans=max2(ans, aint[p]);
    }
}

int main(){
    int m, a, b, c;
    FILE *fout;
    fin=fopen("arbint.in", "r");
    fout=fopen("arbint.out", "w");
    n=read();
    m=read();
    for(int i=1; i<=n; i++)
        v[i]=read();
    //dfs(1, 1, n);
    for(int i=1; i<=m; i++){
        a=read();
        b=read();
        c=read();
        if(a==0){
            left=b;
            right=c;
            ans=0;
            //query();
            fprintf(fout, "%d\n", ans);
        }else{
            poz=b;
            v[poz]=c;
            //update();
        }
    }
    fclose(fin);
    fclose(fout);
    return 0;
}