Pagini recente » Cod sursa (job #331502) | Cod sursa (job #2710568) | Cod sursa (job #1821483) | Cod sursa (job #1266541) | Cod sursa (job #738459)
Cod sursa(job #738459)
#include <fstream>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
using namespace std;
int main()
{
ifstream input("heapuri.in");
ofstream output("heapuri.out");
priority_queue<int, vector<int>, greater<int> > heap;
vector<int> history;
map<int, int> count;
int commands_number;
// start count from 1
history.push_back(-1);
input >> commands_number;
for (int i = 0; i < commands_number; i++) {
int command, value;
input >> command;
switch (command) {
case 1:
input >> value;
history.push_back(value);
count[value]++;
heap.push(value);
break;
case 2:
input >> value;
count[history[value]]--;
break;
case 3:
while (count[heap.top()] == 0)
heap.pop();
output << heap.top() << "\n";
break;
}
}
return 0;
}