Cod sursa(job #1152835)

Utilizator SilverGSilver Gains SilverG Data 24 martie 2014 23:36:43
Problema Arbori de intervale Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 1.4 kb
/*
	Keep It Simple!
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<stdio.h>

#define MaxN 100001
#define MaxV(a,b) ((a)>(b)?(a):(b))

int ArbInt[MaxN], N, x, M, type, a, b, maxvalue;

void UpdateAibInt(int value, int position,int left,int right,int location)
{
	if (left == right)
	{
		ArbInt[location] = value;
	}
	else
	{
		int mid = (left + right) / 2;
		if (position <= mid) UpdateAibInt(value, position, left, mid, location * 2);
		else UpdateAibInt(value, position, mid + 1, right, location * 2 + 1);

		ArbInt[location] = MaxV(ArbInt[2 * location], ArbInt[2 * location + 1]);
	}
}

void QueryAib(int a, int b, int left, int right, int location)
{
	if (a <= left && right <= b)
	{
		if (ArbInt[location] > maxvalue) maxvalue = ArbInt[location];
		return;
	}
	else
	{
		int mid = (left + right) / 2;
		if (a <= mid)  QueryAib(a, b, left, mid, location * 2);
	    if( b > mid )  QueryAib(a, b, mid + 1, right, location * 2 + 1);

	}
}

int main()
{
	freopen("arbint.in", "r", stdin);
	freopen("arbint.out", "w", stdout);

	scanf("%d%d", &N, &M);

	for (int i = 1; i <= N; i++)
	{
		scanf("%d", &x);
		UpdateAibInt(x,i,1,N,1);
	}

	for (int i = 1; i <= M; i++)
	{
		scanf("%d%d%d", &type, &a, &b);
		if (type == 1)
			UpdateAibInt(b, a, 1, N, 1);
		else
		{
			maxvalue = -3;
			QueryAib(a, b, 1, N, 1);
			printf("%d\n", maxvalue);
		}
	}
}