Pagini recente » Profil killer_007 | Cod sursa (job #2402391) | Cod sursa (job #741719) | Cod sursa (job #3358731) | Cod sursa (job #1329281)
#include <fstream>
#include <algorithm>
#define DIM 200005
#define infile "heapuri.in"
#define outfile "heapuri.out"
using namespace std;
ifstream f(infile);
ofstream g(outfile);
int t, op, x, n;
pair<int, int> h[DIM];
int v[DIM], pos[DIM];
int main() {
f >> t;
while (t--) {
f >> op;
if (op == 3) {
g << h[1].first << '\n';
continue;
}
if (op == 1) {
f >> x;
v[++n] = x;
pos[n] = n;
h[n] = make_pair(x, n);
int c = n, p = n/2;
while (p) {
if (h[p].first <= h[c].first)
break;
swap(pos[h[p].second], pos[h[c].second]);
swap(h[p], h[c]);
c = p;
p /= 2;
}
continue;
}
f >> x;
int poz = pos[x];
swap(pos[h[poz].second], pos[h[n].second]);
swap(h[poz], h[n]);
h[n].first = 2000000000;
int p = poz, c = 2*poz;
while (c <= n) {
if (c < n && h[c].first >= h[c + 1].first)
++c;
if (h[p].first > h[c].first) {
swap(pos[h[p].second], pos[h[c].second]);
swap(h[p], h[c]);
}
else
break;
p = c;
c *= 2;
}
p = poz/2; c = poz;
c = n, p = n/2;
while (p) {
if (h[p].first <= h[c].first)
break;
swap(pos[h[p].second], pos[h[c].second]);
swap(h[p], h[c]);
c = p;
p /= 2;
}
}
return 0;
}
//Trust me, I'm the Doctor!