Cod sursa(job #1699936)

Utilizator alex.kosnean97Cosnean Alexandru alex.kosnean97 Data 8 mai 2016 21:16:31
Problema Hotel Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.33 kb
#include <fstream>
#include <iostream>
#include <algorithm>
#define nmax 400000
using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");

int ARB[nmax],S[nmax],D[nmax],N,P,q;
bool B[nmax];
 
void update(int nod, int l, int r, int st,int dr, int type){
        cout << l << ' ' << r << '\n';
        cin >> q;
	 	if(st <= l && r <= dr){
	 		if(type){
		 		 ARB[nod] = S[nod] = D[nod] = r-l+1;
		 		 B[nod] = 1;
	 		 }else ARB[nod] = S[nod] = D[nod] = B[nod] = 0;
	 		 return;
 		}
		 
		 int mid = (l+r)/2;
		 
		 if(mid >= st) update(nod*2,l,mid,st,dr, type);
		 if(mid < dr) update(nod*2+1,mid+1,r,st,dr, type);
		 
		 if(ARB[nod] && !type){
		 	if(mid < st) update(nod*2,l,mid,l,mid,1);
		 	if(mid >= dr) update(nod*2+1,mid+1,r,mid+1,r,1);
		 }
		 
		 if(B[nod*2] && B[nod*2+1]){
		 	ARB[nod] = S[nod] = D[nod] = ARB[2*nod] + ARB[2*nod+1];
		 	B[nod] = 1;
		 }else{
		 	B[nod] = 0;
		 	S[nod] = S[nod*2];
 			D[nod] = D[nod*2+1];
			ARB[nod] = D[nod*2] + S[nod*2+1];	
		 }
}

int main(){
	fin >> N >> P;
	update(1,1,N,1,N,1);
	for(int i = 0,x,y,z;i<P;i++){
		fin >> x;
		if(x == 3) fout << max(ARB[1],max(S[1],D[1])) << '\n';
		else 
		if(x == 2){
			fin >> x >> y;
			update(1,1,N,x,x+y-1,1);
		}else{
			fin >> x >> y;
			update(1,1,N,x,x+y-1,0);
		}
		
		
	}
	
	return 0;
}