Cod sursa(job #2919476)

Utilizator AlexandruBenescuAlexandru Benescu AlexandruBenescu Data 17 august 2022 19:26:59
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <bits/stdc++.h>
#define L 200005
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");

struct MS{
  int t;
  int x;
};
priority_queue <int> v, elim;
MS in[L];
int t1[L], j = 1;

int main(){
  int i, q;
  fin >> q;
  for (i = 0; i < q; i++){
    fin >> in[i].t;
    if (in[i].t != 3)
      fin >> in[i].x;
    else
      in[i].x = 0;
    if (in[i].t == 1)
      t1[j++] = in[i].x;
  }
  for (i = 0; i < q; i++)
    if (in[i].t == 1)
      v.push(-in[i].x);
    else if (in[i].t == 2)
      elim.push(-t1[in[i].x]);
    else{
      while (!elim.empty() && v.top() == elim.top()){
        elim.pop();
        v.pop();
      }
      fout << -v.top() << "\n";
    }
  return 0;
}