Cod sursa(job #964140)

Utilizator Luncasu_VictorVictor Luncasu Luncasu_Victor Data 20 iunie 2013 11:29:59
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");

int n, m, x, y, sol, vv[(1<<18)+13];

void up(int nd, int st, int dr){
	if(st==dr){
		vv[nd]=y;
		return;
	} else {
		int md=(st+dr)/2;
		if(x<=md)up(2*nd,st,md); else
			up(2*nd+1,md+1,dr);
		vv[nd]=max(vv[2*nd], vv[2*nd+1]);
	}
}

void que(int nd,int st,int dr){
	if(x<=st&&dr<=y){
		sol=max(sol,vv[nd]);
		return;
	} else {
		int md=(st+dr)/2;
		if(x<=md)que(2*nd,st,md);
		if(y>md)que(2*nd+1,md+1,dr);
	}
}

int main(){
	int op;
	f >> n >> m;
	for(int i=0;i<n;i++){
		x=i+1;
		f >> y;
		up(1,1,n);
	}
	for(int i=0;i<m;i++){
		f >> op >> x >> y;
		if(op)up(1,1,n); else{
			sol=0;
			que(1,1,n);
			g << sol << "\n";
		}
		//for(int j=0;j<2*n;j++) cout << vv[j] << " " ;
		//cout << "\n";
	}
	
	return 0;
}