Cod sursa(job #2284127)

Utilizator r00t_Roman Remus r00t_ Data 16 noiembrie 2018 21:07:29
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.26 kb
// ConsoleApplication2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
//trie


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <queue>
#include <set>

#define MAX_INT 0x3f3f3f3f;

using namespace std;

ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
//heap

const int MAX_HEAP_SIZE = 16324;
int Heap[MAX_HEAP_SIZE];

int father(int nod) {
	return nod / 2;
}

int left_son(int nod) {
	return 2 * nod + 1;
}

int right_son(int nod) {
	return 2 * nod + 2;
}

int heapMax(int H[]) {
	return H[0];
}

void siftare(int H[], int N, int K) {
	int son;
	do {
		son = 0;
		if (left_son(K) <= N) {
			son = left_son(K);
			if (right_son(K) <= N && H[right_son(K)] > H[left_son(K)]) {
				son = right_son(K);
			}
			if (H[son] <= H[K]) {
				son = 0;
			}
		}

		if (son) {
			swap(H[K], H[son]);
			K = son;
		}
	} while (son);
}

void percolate(int H[], int N, int K) {
	int key = H[K];
	while ((K > 1) && (key > H[father(K)])) {
		H[K] = H[father(K)];
		K = father(K);
	}

	H[K] = key;
}





int main()
{
	multiset<int> my_set1;
	vector<int> hist;

	int n, a, b;
	fin >> n;
	for (int i = 0; i < n; i++) {
		fin >> a;
		if (a == 1) {
			fin >> b;
			my_set1.insert(b);
			hist.push_back(b);
		}
		if (a == 2) {
			fin >> b;
			multiset<int>::iterator it = my_set1.find(hist[b - 1]);
			if (it != my_set1.end()) {
				my_set1.erase(it);
			}
		}
		if (a == 3) {
			multiset<int>::iterator it = my_set1.begin();
			fout << *it << '\n';
		}
	}

}


// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file