Pagini recente » Cod sursa (job #1661261) | Cod sursa (job #1246853) | Cod sursa (job #1167680) | Cod sursa (job #2250957) | Cod sursa (job #1986601)
//#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
#define NR 200005
vector<int> heap, pos(NR, 0), nth;
void add_heap(int x)
{
int p = heap.size();
pos[x] = p;
heap.push_back(x);
nth.push_back(x);
while (p > 0 && heap[p] < heap[p/2])
{
swap(pos[heap[p]], pos[heap[p / 2]]);
swap(heap[p], heap[p / 2]);
p /= 2;
}
}
void remove_heap(int x)
{
heap.erase(heap.begin() + pos[nth[x - 1]]);
make_heap(heap.begin(), heap.end(), greater<int>());
}
int main()
{
int n, i, op, x, current = 0;
fin >> n;
for (i = 0; i < n; ++i)
{
fin >> op;
switch (op)
{
case 1:
fin >> x;
add_heap(x);
break;
case 2:
fin >> x;
remove_heap(x);
break;
case 3:
fout << heap[0] << "\n";
break;
}
}
return 0;
}