Cod sursa(job #412538)

Utilizator xtephanFodor Stefan xtephan Data 5 martie 2010 19:55:27
Problema Heapuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include<stdio.h>
#include<set>

using namespace std;

struct comp {
	
	bool operator()(int i, int j) {
		return i<j;
	}
	
};


multiset<int,comp> heap;
int N;
int poz[40002];

int main() {
	
	int t,k=0,x;
	
	
	freopen("heapuri.in", "r", stdin);
	freopen("heapuri.out", "w", stdout);
	
	scanf("%d",&N);
	
	for(int i=1; i<=N;i++) {
		
		scanf("%d",&t);
		
		if(t==1) {
			scanf("%d",&x);
			heap.insert(x);
			poz[++k]=x;
		}
		
		if(t==2) {
			scanf("%d",&x);
			heap.erase(poz[x]);
		}
		
		
		if(t==3) {
			x=*heap.upper_bound(0);
			printf("%d\n",x);
		}
	}
	
	return 0;
}