Pagini recente » Infoarena Monthly 2014 - Solutii Runda 2 | Implica-te! | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #302040)
Cod sursa(job #302040)
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
#define nm 200010
vector <int>::iterator it;
vector <int> v;
int i, t, x, y, n, j;
int a[nm];
bool cmp(int a, int b)
{
return (a > b);
}
int main()
{
freopen("heapuri.in", "r", stdin);
freopen("heapuri.out","w",stdout);
scanf("%d ", &n);
j = 0;
for (i=1; i<=n; ++i)
{
scanf("%d ", &t);
if (t == 1)
{
scanf("%d ", &x);
a[++j] = x;
v.push_back(x);
push_heap(v.begin(), v.end(), cmp);
}
else
if (t == 2)
{
scanf("%d ", &x);
y = a[x];
it = find(v.begin(), v.end(), y);
v.erase(it);
//if (!is_heap(v.begin(), v.end()))
//printf("BUBA\n");
//make_heap(v.begin(), v.end(), cmp);
}
else
if (t == 3)
{
printf("%d\n", v.front());
}
}
return 0;
}