Pagini recente » Cod sursa (job #1116477) | Cod sursa (job #2203850) | Cod sursa (job #213779) | Cod sursa (job #2244593) | Cod sursa (job #3129293)
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
set<int> ordered_set;
vector <int> heap;
vector<int> insertions;
void sift_up(int x) {
heap.push_back(x);
int i = heap.size() - 1;
while (i > 0 && heap[i] < heap[(i - 1) / 2]) {
swap(heap[i], heap[(i - 1) / 2]);
i = (i - 1) / 2;
}
}
void sift_down() {
int x = heap[0];
heap[0] = heap.back();
heap.pop_back();
int i = 0;
while (2 * i + 1 < heap.size()) {
int left_child = 2 * i + 1;
int right_child = 2 * i + 2;
int min_child = left_child;
if (right_child < heap.size() && heap[right_child] < heap[left_child]) {
min_child = right_child;
}
if (heap[i] > heap[min_child]) {
swap(heap[i], heap[min_child]);
i = min_child;
} else {
break;
}
}
}
int get_min() {
return heap[0];
}
int main() {
int nr_op;
fin >> nr_op;
while (nr_op--) {
int operation;
fin >> operation;
if (operation == 1) {
int x;
fin >> x;
insertions.push_back(x);
ordered_set.insert(x);
} else if (operation == 2) {
int index;
fin >> index;
int x = insertions[index - 1];
ordered_set.erase(x);
} else if (operation == 3) {
fout << *ordered_set.begin() << endl;
}
}
fin.close();
fout.close();
return 0;
}