Cod sursa(job #2848446)

Utilizator alex.prohnitchiAlex Prohnitchi alex.prohnitchi Data 12 februarie 2022 16:29:00
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.7 kb
// Made by Alex Prohnitchi

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

typedef long long ll;

const ll mod=1e9+7;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll minfinit=-1e7;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x)  return cout<<x<<"\n",0
#define sz(s)  (int) s.size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define PI 3.14159265358979

using namespace std;
int ar[100005],t[200006];


void constr(int arr[], int l, int r, int pos) {
	if (l==r) {
		t[pos]=arr[l];
	}
	else {
		int m=(l+r)/2;
		constr(arr,l,m,2*pos);
		constr(arr,m+1,r,2*pos+1);
		t[pos]=max(t[pos*2],t[pos*2+1]);
	}
}
void update(int arr[], int l, int r, int nod, int pos, int newVal) {
	if (l==r) {
		t[nod]=newVal;
	//	arr[l]=pos;
	}
	else {
		int m=(l+r)/2;
		if (pos<=m) {
			update(arr,l,m,2*nod,pos,newVal);
		}
		else {
			update(arr,m+1,r,2*nod+1,pos,newVal);
		}
		t[nod]=max(t[nod*2],t[nod*2+1]);
	}
}
int maxVal(int nod, int l, int r, int tl, int tr) {
	if (tr<l || tl>r) {
		return minfinit;
	}
	else if (tl>=l && tr<=r) {
		return t[nod];
	}
	else {
		int m=(tl+tr)/2;
		return max(maxVal(2*nod,l,r,tl,m),maxVal(2*nod+1,l,r,m+1,tr));
	}
}

void solve() {
	ifstream cin("arbint.in");
	ofstream cout("arbint.out");
	int n,m;
	cin >> n >> m;
	int a,b,type;
	
	for (int i=1; i<=n; i++) {
		cin >> ar[i];
	}
	constr(ar,1,n,1);
	while (m--) {
		cin >> type >> a >> b;
		if (type==0) {
			cout << maxVal(1,a,b,1,n) << '\n';
		}
		else {
			update(ar,1,n,1,a,b);
		}
	}
}

int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	solve();

}