Cod sursa(job #1467276)

Utilizator SilviuIIon Silviu SilviuI Data 3 august 2015 09:29:23
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.44 kb
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <time.h>
#include <bitset>
#include <string>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <limits.h>
#include <algorithm>
#include <deque>
#define nmax 100010
using namespace std;
int i,n,m,arb[nmax*3],x,y,tip;
inline int max(int a,int b) { if (a>b) return a; else return b; }
void build(int nod,int st,int dr)
{
    if (st==dr) { scanf("%d",&arb[nod]); } else
    {
        int m=(st+dr)/2;
        build(nod*2,st,m);
        build(nod*2+1,m+1,dr);
        arb[nod]=max(arb[nod*2],arb[nod*2+1]);
    }
}
void update(int nod,int st,int dr)
{
    if (st>=x && dr<=x) arb[nod]=y; else
    {
        int m=(st+dr)/2;
        if (x<=m) update(nod*2,st,m); else
            update(nod*2+1,m+1,dr);
        arb[nod]=max(arb[nod*2],arb[nod*2+1]);
    }
}
int query(int nod,int st,int dr)
{
    if (st>=x && dr<=y) return arb[nod]; else
    {
        int m=(st+dr)/2,maxx=0;
        if (x<=m) maxx=max(maxx,query(nod*2,st,m));
        if (y>m) maxx=max(maxx,query(nod*2+1,m+1,dr));
        return maxx;
    }
}
int main() {
freopen("arbint.in","r",stdin);
freopen("arbint.out","w",stdout);
scanf("%d %d",&n,&m);
build(1,1,n);
for (i=1;i<=m;i++) {
    scanf("%d %d %d",&tip,&x,&y);
    if (tip==0) printf("%d\n",query(1,1,n)); else
        update(1,1,n);
}
return 0;
}