Pagini recente » Cod sursa (job #2281171) | Cod sursa (job #1797347) | Cod sursa (job #770349) | Cod sursa (job #1268887) | Cod sursa (job #2292089)
#include <bits/stdc++.h>
#define N_max 200001
using namespace std;
int heap[N_max], ap[N_max], nod[N_max];
void minheap(int n){
while(heap[n] < heap[n / 2]){
swap(heap[n], heap[n/2]);
ap[n] = nod[n / 2];
ap[n / 2] = nod[n];
n /= 2;
}
}
int stergere(int poz, int n)
{
swap(heap[n], heap[poz]);
swap(ap[n], ap[poz]);
n--;
int i = poz;
while (heap[i] > heap[i * 2] && i * 2 <= n){
swap(heap[i], heap[i * 2]);
ap[i] = nod[i * 2];
ap[i * 2] = nod[i];
i *= 2;
}
return n;
}
int main()
{
ifstream f("heapuri.in");
ofstream g("heapuri.out");
int N, j;
f>>N;
int n = j = 0;
for (int i = 1; i <= N; i++){
int c, x;
f>>c;
if (c == 1){
f>>x;
n++;
j++;
nod[n] = n;
ap[j] = n;
heap[n] = x;
minheap(n);
}
if (c == 2)
{
f>>x;
n = stergere(ap[x], n);
}
if (c == 3)
{
g<<heap[1]<<"\n";
}
}
return 0;
}