ウホウホゴリラッホ

主に勉強したことをまとめていきます。twitter:@pytran3

priority_queueの使い方

注意点

  • デフォルトでは大きいものからpopされる(Python, Javaの逆)

    実装例

priority_queue<ll> p;
p.push(2);
p.push(1);
while(p.size()) {
  cout << p.top() << endl; //参照
  p.pop(); //削除
}
// 昇順に取り出したい場合はgreaterを使う
// 真ん中のvectorは格納するデータ構造
using PQ = priority_queue<ll, vector<ll>, greater<ll>>;

//emplaceも使える
using Pair = pair<ll, ll>;
priority_queue<Pair, vector<Pair>, greater<Pair>> q;
REP(i, n) {
  ll a, b;
  cin >> a >> b;
  q.emplace(a, b);
}