ollpu's blog

By ollpu, history, 4 years ago, In English

Just leaving this here:

auto q = priority_queue(greater(), vector{pair{0ll, 0}});
// or
auto q = priority_queue(greater(), vector{tuple{0ll, 0, 0}});

Only works in GCC 9.1 and up, so you have to submit as GCC C++17 64bit in Codeforces.

  • Vote: I like it
  • +52
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +12 Vote: I do not like it

I like to write:

template<class T>
using pqt = priority_queue<T,vector<T>,greater<T>>

...

pqt<tuple<int,int,int>> q;

Its a bit longer than your option but you dont need to worry about the compiler version. Alternatively you can just use negative values to order correctly in the priority queue, but I dont like that either

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it
template<class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<class T> using maxpq = priority_queue<T, vector<T>>;
template<class A, class B> using pq = priority_queue<A, vector<A>, B>;
»
4 years ago, # |
Rev. 2   Vote: I like it +34 Vote: I do not like it

not related, but my friend likes to write

#define benq queue
#define pbenq priority_queue

:D

»
4 years ago, # |
Rev. 2   Vote: I like it +6 Vote: I do not like it

Why bother?..

set<pair<int, int>> q = {{0ll, 0}};
// or
set<tuple<int, int, int>> q = {{0LL, 0, 0}};