Pagini recente » Cod sursa (job #569494) | Cod sursa (job #1863160) | Cod sursa (job #2917953) | Cod sursa (job #2719021) | Cod sursa (job #1615922)
# include <fstream>
# include <algorithm>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
const int MAX_HEAP_SIZE = 200010;
int h[MAX_HEAP_SIZE];
int r[MAX_HEAP_SIZE];
int x, t, p;
bool comp(const int& a, const int& b) {
return a > b;
}
int Search(int val) {
if (val == h[1])
return 1;
int i, j;
i = j = 1;
do {
if (val > h[i])
i = i << 1;
if (val > h[j])
j = (j << 1) + 1;
} while (val != h[i] && val != h[j] && i <= h[0] && j <= h[0]);
return ((val == h[i]) ? i : j);
}
int main() {
make_heap(h+1, h+h[0]+1, comp);
fin >> t;
while (t--) {
fin >> p;
if (p == 1) {
fin >> x;
h[++h[0]] = r[++r[0]] = x;
push_heap(h+1, h+h[0]+1, comp);
continue;
}
if (p == 2) {
int i;
fin >> x;
i = Search(r[x]);
pop_heap(h+i, h+h[0]+1, comp);
h[0]--;
continue;
}
if (p == 3) {
fout << h[1] << "\n";
continue;
}
}
fin.close();
fout.close();
return 0;
}