Cod sursa(job #1866623)

Utilizator radu.leonardoThe Doctor radu.leonardo Data 3 februarie 2017 13:13:38
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <cstdio>
#define NMAX 100001
using namespace std;

FILE*f=freopen("arbint.in","r",stdin);
FILE*g=freopen("arbint.out","w",stdout);
int n,m,oak[2 * NMAX],t,a,b;

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

inline void build()
{
  for (int i=n-1;i;--i)      oak[i] = max( oak[i<<1],oak[(i<<1)|1]);
}

inline void modify(int p, int value)
{ int tmp;
  p+=n-1;oak[p]=value;

            while (p > 1) {
                tmp = p >> 1;
                oak[tmp] = max(oak[p], oak[p ^ 1]);
                p = tmp;
            }
}

inline int query(int st, int dr)
{
int  rez = 0;st+=n-1;dr+=n-1;
    while (st <= dr) {
        rez = max(rez, max(oak[st], oak[dr]));
        st = (st + 1) >> 1;
        dr = (dr - 1) >> 1;
            }
  return rez;
}

int main() {
  scanf("%d %d", &n,&m);
  for (int i = 0; i < n; ++i) scanf("%d", &oak[n+i]);
  build();
  while(m--)
  { scanf("%d %d %d", &t,&a,&b);
    if(t==0) printf("%d\n",query(a,b));
    else modify(a,b);
  }


}