Cod sursa(job #302039)

Utilizator snaked31Stanica Andrei snaked31 Data 8 aprilie 2009 17:03:11
Problema Heapuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#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;
}