Cod sursa(job #244527)

Utilizator andrei-alphaAndrei-Bogdan Antonescu andrei-alpha Data 15 ianuarie 2009 12:34:13
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
using namespace std;

#include <bitset>
#include <queue>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define II inline
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define IN  "heapuri.in"
#define OUT "heapuri.out"
#define N_MAX 1<<18

int K,N;
bool P[N_MAX];
typedef pair<int,int> pi;

II void scan()
{
	freopen(IN,"r",stdin);
	freopen(OUT,"w",stdout);
	scanf("%d",&K);
}

priority_queue<pi,vector<pi>,greater<pi> > Q;

II void solve()
{
	int t,x;
	FOR(i,1,K)
	{
		scanf("%d",&t);
		if(t!=3)
			scanf("%d",&x);
		if(t==1)
		{
			P[++N] = true;
			Q.push( mp(x,N) );
		}	
		if(t==2)
			P[x] = false;
		if(t==3)
		{
			for(;!P[ Q.top().s ];Q.pop());
			printf("%d\n",Q.top().f);
		}	
	}
}

int main()
{
	scan();
	solve();
	return 0;
}