Pagini recente » Cod sursa (job #2359106) | Cod sursa (job #577131) | Cod sursa (job #100323) | Cod sursa (job #1531081) | Cod sursa (job #1615927)
# 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) {
int st, dr, mid;
st = 1; dr = h[0];
while (st <= dr) {
mid = st + ((dr - st) / 2);
if (h[mid] > val)
dr = mid - 1;
else if (h[mid] <= val)
st = mid + 1;
}
return dr;
}
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;
}