Pagini recente » Cod sursa (job #2378902) | Cod sursa (job #2651943) | Cod sursa (job #2903306) | Cod sursa (job #2211405) | Cod sursa (job #1076267)
#include <cstdio>
#include <bitset>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
priority_queue<int, vector<int>, greater<int> > PQ;
vector<int> inserat_element;
bool deletat[200001];
int main()
{
FILE *in, *out;
in = fopen ("heapuri.in", "r");
out = fopen ("heapuri.out", "w");
int n; fscanf (in, "%d", &n);
inserat_element.push_back(0);
for (int i = 1; i <= n; ++i)
{
int tip_operatie; fscanf (in, "%d", &tip_operatie);
int x;
switch (tip_operatie)
{
case 1:
fscanf (in, "%d", &x);
PQ.push(x);
inserat_element.push_back(x);
break;
case 2:
fscanf (in, "%d", &x);
if (inserat_element[x] > 200001) while (1);
deletat[inserat_element[x]] = true;
break;
case 3:
for (int j = PQ.top(); deletat[j] == true && PQ.size() > 0; j = PQ.top())
PQ.pop();
fprintf (out, "%d\n", PQ.top());
break;
default:
throw new exception();
}
}
return 0;
}