Pagini recente » Cod sursa (job #1334538) | Cod sursa (job #2099990) | Cod sursa (job #416390) | Cod sursa (job #1627031) | Cod sursa (job #2294607)
#include <bits/stdc++.h>
using namespace std;
FILE *fin = fopen ("heapuri.in", "r"), *fout = fopen ("heapuri.out", "w");
const int MAXN = 2e5;
int yep[MAXN + 1], poz[MAXN + 1], v[MAXN + 1];
int sz, nr;
void bambo (int x, int y) {
swap (yep[x], yep[y]);
poz[yep[x]] = x;
poz[yep[y]] = y;
}
void up (int nod) {
while (nod != 1 && yep[nod] < yep[nod / 2]) {
bambo (nod, nod / 2);
nod = nod / 2;
}
}
void chromosomes (int nod) {
int hump = nod;
if (2 * nod <= sz && yep[2 * nod] < yep[hump])
hump = 2 * nod;
if (2 * nod + 1 <= sz && yep[2 * nod + 1] < yep[hump])
hump = 2 * nod + 1;
if (hump != nod) {
bambo (nod, hump);
chromosomes (hump);
}
}
void erase (int x) {
if (x < sz) {
yep[x] = yep[sz--];
poz[yep[x]] = x;
chromosomes (x);
up (x);
}
else {
sz--;
}
}
void add (int x) {
yep[++sz] = x;
poz[x] = sz;
up (sz);
}
int main() {
int t, type, x;
fscanf (fin, "%d", &t);
sz = 0;
nr = 0;
while (t--) {
fscanf (fin, "%d", &type);
if (type == 1) {
fscanf (fin, "%d", &x);
v[++nr] = x;
add (x);
}
else if (type == 2) {
fscanf (fin, "%d", &x);
x = v[x];
erase (poz[x]);
}
else {
fprintf (fout, "%d\n", yep[1]);
}
}
fclose (fin);
fclose (fout);
return 0;
}