Cod sursa(job #1140896)

Utilizator irimiecIrimie Catalin irimiec Data 12 martie 2014 12:53:54
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>
#include <iostream>
#include <queue>

using namespace std;

ifstream f("heapuri.in");
ofstream g("heapuri.out");

const int maxn = 200010;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > heap;
int n, k;
bool del[maxn];

int main()
{
	int x, type;
	k = 0;
	f >> n;
	while(n--)
	{
		f >> type;
		if(type == 1)
		{
			f >> x;
			heap.push(make_pair(x, ++k));
		}
		else if(type == 2)
		{
			f >> x;
			del[x] = true;
		}
		else
		{
			while(del[heap.top().second])
				heap.pop();
			g << heap.top().first << '\n';
		}
	}
}