Cod sursa(job #966672)

Utilizator dropsdrop source drops Data 26 iunie 2013 13:46:51
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <ctime>
#include <string>
#include <algorithm>
using namespace std;
ifstream ff("arbint.in");
ofstream gg("arbint.out");

int n, m, aa[(1<<18)+1], s, a, b;

void upd(int n, int l, int r){
	if(l==r){ aa[n]=b; } else {
		int m=(l+r)/2;
		if(a<=m)upd(2*n, l, m); else
			upd(2*n+1, m+1, r); 
		aa[n]=max(aa[2*n], aa[2*n+1]); }
}

void qry(int n,int l,int r){
	if(a<=l&&r<=b){ s=max(s,aa[n]); } else {
		int m=(l+r)/2;
		if(a<=m)qry(2*n, l, m);
		if(b>m)qry(2*n+1, m+1, r); }
}

int main(){
	int op;
	ff >> n >> m;
	for(int i=1;i<=n;i++){
		ff >> b;
		a=i;
		upd(1,1,n);
	}
	for(int i=1;i<=m;i++){
		ff >> op >> a >> b;
		if(op){ upd(1,1,n); } else {
			s=0;
			qry(1,1,n);
			gg << s << "\n"; }
	}
}