Pagini recente » Cod sursa (job #2130353) | Cod sursa (job #2469645) | Cod sursa (job #2440439) | Cod sursa (job #1040397) | Cod sursa (job #633484)
Cod sursa(job #633484)
#include<cstdio>
#include<vector>
using namespace std;
// dsfsdfdsfsd sdf sdf sdf sdf
// dsfsdfdsfsd sdf sdf sdf sdf
// dsfsdfdsfsd sdf sdf sdf sdf
// dsfsdfdsfsd sdf sdf sdf sdf
int A[200001], no;
void Coboara(int h[], int &n, int i){
int fiu, aux = h[i];
while (i <= n/2){
fiu = 2 * i;
if (fiu + 1 <= n && h[fiu+1] < h[fiu]) fiu++;
if (h[i] > h[fiu]){
h[i] = h[fiu];
i = fiu;
}
else break;
}
h[i] = aux;
}
void Urca(int h[], int &n, int i){
int tata = i/2, key = h[i];
while (i > 1 && key < h[tata]){
h[i] = h[tata];
i = tata; tata = i/2;
}
h[i] = key;
}
void Insereaza(int h[], int &n, int &x){
h[++n] = x;
A[++no] = x;
Urca(h, n, n);
}
void Sterge(int h[], int &n, int &x){
int i;
for (i = 1; h[i] != A[x]; i++);
h[i] = h[n--];
Coboara(h, n, i);
Urca(h, n, i);
}
int main(){
freopen("heapuri.in", "r", stdin);
freopen("heapuri.out", "w", stdout);
int n = 0, i, cod, x, op;
scanf ("%d", &op);
int h[op+1];
for (i = 0; i < op; i++){
scanf("%d", &cod);
if (cod == 3) printf("%d\n", h[1]);
else{
scanf("%d", &x);
if (cod == 1) Insereaza(h, n, x);
else Sterge(h, n, x);
}
}
return 0;
}