Pagini recente » Cod sursa (job #2065197) | Cod sursa (job #1732864) | Cod sursa (job #2490068) | Cod sursa (job #2273809) | Cod sursa (job #2087664)
#include <iostream>
#include <fstream>
//#include<bits/stdc++.h>
using namespace std;
#define in f
#define out g
ifstream f ("heapuri.in");
ofstream g ("heapuri.out");
const int MAX_SIZE = 1e6;
int n, x, y, code, length, k;
int heap[MAX_SIZE], order[MAX_SIZE];
void insert (int pos) {
if (pos == 1)
return;
if (heap[pos] < heap[pos / 2]) {
swap(heap[pos], heap[pos / 2]);
insert(pos / 2);
}
return;
}
void remove(int pos) {
if (2 * pos > length)
return;
if ((heap[pos] > heap[2 * pos + 1] && (2 * pos + 1) > length) || heap[pos] > heap[2 * pos]) {
if (heap[2 * pos + 1] > heap[2 * pos] || (2 * pos + 1) > length) {
swap(heap[2 * pos], heap[pos]);
remove(2 * pos);
} else {
swap(heap[2 * pos + 1], heap[pos]);
remove(2 * pos + 1);
}
}
return;
}
void minn() {
out << heap[1] << "\n";
}
int main() {
in >> n;
for(int i = 1; i <= n; i++) {
in >> code;
if(code == 1) {
in >> x;
k++;
order[k] = x;
length++;
heap[length] = x;
insert(length);
}
if(code == 2) {
in >> x;
int pos = 0;
for (int j = 1; j <= length; j++) {
if (heap[j] == order[x]) {
pos = j;
j = length;
}
}
swap(heap[pos], heap[length]);
heap[length] = 0;
length--;
remove(pos);
}
if(code == 3) {
minn();
}
}
}