█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6845

Problema 0xb0 - Implementar una cola de prioridad

  • Autor: Juan Jr
  • Fecha: 2023-01-12 06:14:08 UTC (Hace casi 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.004 s 1 KBi
#2
Correcto
0.005 s 1 KBi
#3
Correcto
0.005 s 1 KBi
#4
Correcto
0.005 s 1 KBi
#5
Correcto
0.005 s 1 KBi
#6
Correcto
0.005 s 1 KBi
#7
Correcto
0.004 s 1 KBi
#8
Correcto
0.007 s 1 KBi
#9
Correcto
0.005 s 1 KBi
#10
Correcto
0.08 s 4 KBi
#11
Correcto
0.031 s 4 KBi
#12
Correcto
0.035 s 2 KBi
#13
Correcto
0.066 s 4 KBi
#14
Correcto
0.069 s 4 KBi
#15
Correcto
0.048 s 2 KBi
#16
Correcto
0.07 s 4 KBi
#17
Correcto
0.103 s 4 KBi
Puntos totales: 100 / 100

Código

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
#define pb push_back
#define ff first
#define ss second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define rforn(i, n) for (int i = n; i >= 0; --i)
#define form(i, n, m, x) for (int i = n; i < m; i += x)
#define rform(i, n, m, x) for (int i = n; i >= m; i -= x)

#ifdef LOCAL
  #include "/debug/debug.h"
#else
  #define dbg(x...)
  #define endl '\n'
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  struct Data {
    string s;
    int p;
    
    bool operator < (const Data &o) const {
      if (p == o.p) return s > o.s;
      return p < o.p;
    }
  };
  priority_queue<Data> pq;
  int n; cin >> n;
  while (n--) {
    string op; cin >> op;
    if (op == "Insert") {
      Data x;
      cin >> x.s >> x.p;
      pq.push(x);
    } else if (op == "GetMax") {
      cout << pq.top().s << endl;
    } else {
      pq.pop();
    }
  }
  return 0;
}

/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 * DON'T GET STUCK ON ONE APPROACH
 */