Cod sursa(job #2232115)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 17 august 2018 13:46:38
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.12 kb
#include <fstream>
#include <vector>
#include <bitset>
#include <stack>
//#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false), cin.tie(0);

using namespace std;

ifstream cin("arbint.in");
ofstream cout("arbint.out");

const int N = 1e5 + 7;

const int INF = 0x3f3f3f3f;

int v[4 * N];

void update(int st, int dr, int nod, int poz, int val)
{
	if(st == dr)
	{
		v[nod] = val;
		return ;
	}
	
	int mid = (st + dr) / 2;
	if(poz <= mid)
		update(st, mid, 2 * nod, poz, val);
	else
		update(mid + 1, dr, 2 * nod + 1, poz, val);
	v[nod] = max(v[nod * 2], v[nod * 2 + 1]);
}

int ans;

void query(int st, int dr, int nod, int a, int b)
{
	if(a <= st && dr <= b)
	{
		ans = max(ans, v[nod]);
		return ;
	}
	int mid = (st + dr) / 2;
	if(a <= mid)
		query(st, mid, nod * 2, a, b);
	if(b > mid)
		query(mid + 1, dr, nod * 2 + 1, a, b);
}

main()
{
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		update(1, n, 1, i, x);
	}
	while(m--)
	{
		int q;
		cin >> q;
		int a, b;
		cin >> a >> b;
		if(q == 1)
			update(1, n, 1, a, b);
		else
		{
			ans = -INF;
			query(1, n, 1, a, b);
			cout << ans << '\n';
		}
	}
}