Cod sursa(job #1653937)

Utilizator vladttturcuman vlad vladtt Data 16 martie 2016 18:20:51
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
// Tree Sequence.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <fstream>
#include <vector>

#define NMax 100010
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");


int p[4 * NMax];

int a, b, i, n, m, t;

int max(int a, int b)
{
	return a < b ? b : a;
}

void Update(int nod,int in,int sf,int a,int b)
{
	if (in == sf)
	{
		p[nod] = b;
		return;
	}

	int mij = (in + sf) / 2;

	if (mij >= a)
		Update(nod * 2, in, mij, a, b);
	else
		Update(nod * 2 + 1, mij + 1, sf, a, b);

	p[nod] = max(p[nod*2],p[nod*2+1]);
}


int Get(int nod, int in, int sf, int a, int b)
{
	if (in >= a && sf<=b)
		return p[nod];

	int mij = (in + sf) / 2;
	int mx = 0;


	if (mij >= a)
		mx=Get(nod * 2, in, mij, a, b);
	if (mij < b)
		mx = max(mx, Get(nod * 2 + 1, mij + 1, sf, a, b));

	return mx;
}

int main()
{

	fin >> n>>m;

	for (i = 1; i <= n; i++)
	{
		fin >> a;
		Update(1, 1, n, i, a);
	}

	for (i = 1; i <= m; i++)
	{
		fin >> t >> a >> b;
		if (t)
		{
			Update(1, 1, n, a, b);
			continue;
		}
		fout << Get(1,1,n,a,b)<<'\n';
	}



    return 0;
}