Cod sursa(job #359743)

Utilizator cristiprgPrigoana Cristian cristiprg Data 28 octombrie 2009 10:50:57
Problema Heapuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <cstdio>
#include <queue>
#define DIM 200005

struct nod
{
	int index;
	nod *next;
};

using namespace std;
FILE *f = fopen("heapuri.in", "r");
FILE *g = fopen("heapuri.out", "w");

const int INF = 1 << 30;
int v[DIM],nr_el;


int main()
{
	int  n, i, op,  x;
	nod *p = NULL;
	p -> next = NULL;
	
	fscanf(f, "%d", &n);
	for (i = 1; i <= n; ++i)
	{
		fscanf(f, "%d", &op);
		if (op == 1)
		{
			fscanf(f, "%d", &x);
			v[++nr_el] = x;
			
			if(p == NULL)
			{
				p = new nod;
				p.index = nr_el;
				p -> NULL;
			}
			
			else
			{
				nod *t = p;
				while (p != NULL && v[ t -> index ] <= v[nr_el])
					t = t -> next;
				
				nod *t2 = new nod;
				t2 -> index = nr_el;
				t2 -> next = t;
				// ma rog
				
			}
		}
		
		else
			if (op == 2)
			{
				fscanf(f, "%d", &x);
				v[x] = INF;
			}
			
			else
			{
				int min = INF;
				for (int k = 1; k <= nr_el; ++k)
					if (min > v[k])
						min = v[k];
				fprintf(g , "%d\n", min);
			}
	}
		
	
	fclose(f);
	fclose(g);
	return 0;
}