Cod sursa(job #2450095)

Utilizator ejoi2019Ejoi 2019 ejoi2019 Data 21 august 2019 20:23:15
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#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;
}