Cod sursa(job #1987824)

Utilizator virtualityBbbbbbbbbbbbbbbbbb virtuality Data 1 iunie 2017 09:08:13
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include<bits/stdc++.h>
using namespace std;
const int N=400020;
int a[N], n;
int x, y, pos, maxi;
void update(int nod, int st, int dr){
	if(st==dr){
		a[nod]=x;
		return;
	}
	int m=(st+dr)/2;
	if(pos<=m) update(nod*2, st, m); else update(2*nod+1, m+1, dr);
	a[nod]=max(a[nod*2], a[nod*2+1]);
}
void query(int nod, int st, int dr){
	if(st >= y && dr<=x){
		maxi=max(maxi, a[nod]);
		return;
	}
	int m=(st+dr)/2;
	if(y<=m) query(nod*2, st, m);
	if(x>m) query(nod*2+1, m+1, dr);
}
int main(){
	int m, k;
	ifstream f("arbint.in");
	ofstream g("arbint.out");
	f>>n>>m;
	for(int i=1;i<=n;i++){
		f>>x;
		pos=i;
		update(1, 1, n);
	}
	
	while(m--){
		f>>k>>y>>x;
		if(k)pos=y,update(1, 1, n); else maxi=-1, query(1, 1, n), g<<maxi<<'\n';
	}
}