Cod sursa(job #1244594)

Utilizator ducu34Albastroiu Radu Gabriel ducu34 Data 17 octombrie 2014 20:39:07
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include<fstream>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int tip,a,b,n,i,m,v[100001],H[400005],sol;
void umplere(int l,int r,int p)
{
	if(l==r)
	{
		H[p]=v[l];
	}
	else
	{
		int w=(l+r)/2;
		umplere(l,w,p*2);
		umplere(w+1,r,p*2+1);
		H[p]=max(H[p*2],H[p*2+1]);
	}
}
void update(int st,int dr,int p)
{
	if(st==dr)
	{
		H[p]=b;
		return;
	}
	int w=(st+dr)/2;
	if(a<=w)
		update(st,w,p*2);
	else
		update(w+1,dr,p*2+1);
	H[p]=max(H[p*2],H[p*2+1]);
}
void maxim(int st,int dr,int p)
{
	if(st>=a && dr<=b)
	{
		sol=max(sol,H[p]);
		return;
	}
	int w=(st+dr)/2;
	if(w+1<=b)
		maxim(w+1,dr,p*2+1);
	if(w>=a)
		maxim(st,w,p*2);
}
int main()
{
	fin>>n>>m;
	for(i=1;i<=n;i++)
		fin>>v[i];
	umplere(1,n,1);
	for(i=1;i<=m;i++)
	{
		fin>>tip>>a>>b;
		if(tip)
			update(1,n,1);
		else
		{
			sol=0;
			maxim(1,n,1);
			fout<<sol<<"\n";
		}
	}
	return 0;
}