Cod sursa(job #1646878)

Utilizator qwertyuiTudor-Stefan Berbinschi qwertyui Data 10 martie 2016 18:04:47
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream>
#include <fstream>
#include <queue>

using namespace std;

ifstream fin ("heapuri.in");
ofstream fout ("heapuri.out");

struct heap {
	int x, pos;
	bool operator< (const heap &a) const
	{
		return x > a.x;
	}
	};

priority_queue <heap> myHeap;
bool used[250000];
int N, M;

int main()
{
	fin >>N;
	for (int i = 1; i <= N; ++i)
	{
        int type,x;
        heap temp;
        fin >>type;

        if (type == 1)
		{
			fin >>x;
			temp.x = x;
			temp.pos = ++M;
			myHeap.push(temp);
		}

		if (type == 2)
		{
            fin >>x;
            used[x] = 1;
		}
		if (type == 3)
		{
            while (!myHeap.empty() && used[myHeap.top().pos])
				myHeap.pop();
			fout <<myHeap.top().x <<'\n';
		}
	}

    return 0;

}