Cod sursa(job #461143)

Utilizator darrenRares Buhai darren Data 5 iunie 2010 18:34:55
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include<fstream>
#include<algorithm>
using namespace std;

int n, m, ari[100000 * 4 + 10];
int a, b, p, v, mx;

void query(int nod, int st, int dr)
{
	if (a <= st && dr <= b)
	{
		mx = max(ari[nod], mx);
		return;
	}
	int mj = (st + dr) >> 1;
	if (a <= mj)
		query(2 * nod, st, mj);
	if (b > mj)
		query(2 * nod + 1, mj + 1, dr);
}
void update(int nod, int st, int dr)
{
	if (st == dr)
	{
		ari[nod] = v;
		return;
	}
	int mj = (st + dr) >> 1;
	if (p <= mj)
		update(2 * nod, st, mj);
	else
		update(2 * nod + 1, mj + 1, dr);
	ari[nod] = max(ari[2 * nod], ari[2 * nod + 1]);
}

int main()
{
	ifstream fin("arbint.in");
	ofstream fout("arbint.out");
	fin >> n >> m;

	for (int i = 1, aux; i <= n; ++i)
	{
		fin >> aux;
		p = i, v = aux;
		update(1, 0, 100000);
	}
	for (int i = 1, aux; i <= m; ++i)
	{
		fin >> aux;
		switch (aux)
		{
		case 0:
			fin >> a >> b;
			mx = 0;
			query(1, 0, 100000);
			fout << mx << '\n';
			break;
		case 1:
			fin >> p >> v;
			update(1, 0, 100000);
			break;
		}
	}
}