Pagini recente » Cod sursa (job #3272880) | Cod sursa (job #2064437) | Cod sursa (job #2378917) | Cod sursa (job #171027) | Cod sursa (job #3238114)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int heap[200001];
int a[100001];
int heapLen;
int aLen;
void updateHeap(int pos) {
int j = pos;
while (j >= 2 && heap[j] < heap[j / 2]) {
swap(heap[j], heap[j / 2]);
j /= 2;
}
}
void deleteHeap(int number) {
int pos = 0;
for (int i = 1; i <= heapLen; ++i) {
if (heap[i] == number) {
pos = i;
break;
}
}
swap(heap[pos], heap[heapLen]);
--heapLen;
for (int i = 1; i <= heapLen; ++i) {
updateHeap(i);
}
}
void insertHeap(int number) {
heap[++heapLen] = number;
updateHeap(heapLen);
}
int main() {
int n;
fin >> n;
for (int i = 1; i <= n; ++i) {
int op;
fin >> op;
if (op == 1) {
fin >> a[++aLen];
insertHeap(a[aLen]);
} else if (op == 2) {
int pos;
fin >> pos;
deleteHeap(a[pos]);
} else {
fout << heap[1] << '\n';
}
}
return 0;
}