Cod sursa(job #412664)

Utilizator pykhNeagoe Alexandru pykh Data 5 martie 2010 20:59:59
Problema Arbori de intervale Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 1.14 kb
#include<stdio.h>
const char in[]="arbint.in", out[]="arbint.out";
int st, dr, val, n, v[100005], max, poz;

inline int maxim(int a, int b)
	{
		return a > b ? a : b ;
}

void update(int nod, int lo, int hi)
{
	if( lo == hi)
	{
		v[ nod ] = val;
		return ;
	}
	int m = ( lo + hi ) / 2;
	if( poz <= m ) update ( 2 * nod, lo, m);
	else update ( 2 * nod + 1, m + 1, hi);
	v[ nod ] = maxim( v[ 2 * nod ] , v[ 2 * nod + 1]);
}

void query(int nod, int lo, int hi)
	{
		if(st <= lo && hi <= dr)
			{
				if( max < v[ nod ] ) max = v[ nod ];
				return;
			}
		int m=(lo+hi)/2;
		if( st <= m ) query ( 2 * nod , lo , m);
		if( m < dr ) query ( 2 * nod +1 , m + 1 , hi);
}
		
  
int main()
	{int m, a, b, op;
		freopen(in,"r",stdin);
		freopen(out,"w",stdout);
		scanf("%d%d", &n, &m);
		for(int i = 1 ; i <= n; ++i)
		{
			scanf("%d", &val);
			poz=i;
			update(1, 1, n);
		}
		for(; m-- ; )
		{
			scanf("%d%d%d", &op, &a, &b);
			if(!op)
			{
				max=-1;
				st=a, dr=b;
				query(1 , 1, n);
				printf("%d\n", max);
			}
			else {
				poz=a, val=b;
				update(1, 1, n);
			}
		}
		return 0;
	}