Cod sursa(job #447951)

Utilizator ooctavTuchila Octavian ooctav Data 2 mai 2010 10:40:21
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.25 kb
// arbint2.cpp : Defines the entry point for the console application.
//

#include <cstdio>
#include<iostream>
using namespace std;

const int NMAX = 100010;

int N, M;
int A[NMAX];
int Arb[1 << 18];
int x, y;
int maxim;

void query(int creanga, int st, int dr)
{
	if(x <= st &&  dr <= y)
	{
		maxim = max(maxim, Arb[creanga]);
		return;
	}

	int mij = (st + dr) / 2;
	if(x <= mij)
		query(2*creanga, st, mij);
	if(mij + 1 <= y)
		query(2*creanga + 1, mij + 1, dr);

}

void update(int creanga ,int st, int dr)
{
	if(st == dr)
	{
		Arb[creanga] = y;
		return;
	}

	int mij = (st + dr) / 2;
	if(x <= mij)
		update(2 * creanga, st, mij);
	else
		update(2 * creanga + 1, mij + 1, dr);

	Arb[creanga] = max(Arb[2*creanga], Arb[2*creanga + 1]);
}

void citire()
{
	int iden;

	scanf("%d%d", &N, &M);
	for(int i = 1 ; i <= N ; i++)
	{
		scanf("%d", &A[i]);
		x = i;
		y = A[i];
		update(1, 1, N);
	}

	for(int i = 1 ; i <= M ; i++)
	{
		scanf("%d %d %d", &iden, &x, &y);
		if(iden == 0)
		{
			maxim = -1;
			query(1, 1, N);
			printf("%d\n", maxim);
		}
		else
			update(1, 1, N);
	}


}

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


	return 0;
}