Cod sursa(job #396195)

Utilizator AndreiDDiaconeasa Andrei AndreiD Data 14 februarie 2010 18:38:51
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

#define file_in "heapuri.in"
#define file_out "heapuri.out"

#define Nmax 201001

priority_queue< pair < int,int > , vector < pair <int,int> > , greater < pair <int,int> > > H;
vector<bool> V(Nmax);
int T,val,nr,tip;

int main()
{
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	scanf("%d", &T);
	
	while(T--)
	{
		scanf("%d", &tip);
		
		if (tip==1)
		{
			++nr;
			scanf("%d", &val);
			H.push(make_pair(val,nr));
		}
		else
		if (tip==2)
        {
			scanf("%d", &val);
			V[val]=true;
		}
		else
		{
			while(V[H.top().second])
				H.pop();
			printf("%d\n", H.top().first);
		}
	}
	
	
	
	fclose(stdin);
	fclose(stdout);
	
	
	return 0;
	
}