Pagini recente » Cod sursa (job #803047) | Cod sursa (job #1366167) | Cod sursa (job #2136351) | Cod sursa (job #2229831) | Cod sursa (job #2450095)
#include <cstdio>
#include <map>
#include <queue>
using namespace std;
const int N = (int) 2e5 + 7;
int n;
int bagat[N], top;
priority_queue <int> pq;
map <int, int> sters;
int main() {
freopen ("heapuri.in", "r", stdin);
freopen ("heapuri.out", "w", stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int op;
scanf("%d", &op);
if (op == 1) {
int x;
scanf("%d", &x);
x = -x;
bagat[++top] = x;
pq.push(x);
}
if (op == 2) {
int j;
scanf("%d", &j);
sters[bagat[j]]++;
}
if (op == 3) {
while (1) {
int x = pq.top();
if (sters[x]) {
sters[x]--;
pq.pop();
} else {
break;
}
}
printf("%d\n", -pq.top());
}
}
return 0;
}