Cod sursa(job #369152)

Utilizator Bogdan_tmmTirca Bogdan Bogdan_tmm Data 27 noiembrie 2009 09:37:27
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include<stdio.h>
#include<queue>
#include<bitset>
using namespace std;
typedef pair <int,int> p;
struct  cmp
{
	bool operator () (const p x,const p y) const
	{
		return x.first>y.first;
	}
};
int n,op,x,which;
bitset <200001> deleted;
priority_queue <p,vector <p>,cmp > heap;
int main()
{
	freopen("heapuri.in","r",stdin);
	freopen("heapuri.out","w",stdout);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&op);
		if(op==3)
		{
			for(;deleted[heap.top().second];heap.pop());
			printf("%d\n",heap.top().first);
			continue;
		}
		scanf("%d",&x);
		if(op==1)
		{
			heap.push(p(x,++which));
		}
		else
		{
			deleted[x]=true;
		}
	}
	return 0;
}