Last active
September 5, 2020 12:02
-
-
Save cgiosy/14d0076e7f735c0a05890ad3c8071096 to your computer and use it in GitHub Desktop.
PQ 두 개로 최소/최대만 필요한 set 대체하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T=int, class O=less<T>> | |
struct heap_set { | |
priority_queue<T, vector<T>, O> q, del; | |
const T& top() const { return q.top(); } | |
int size() const { return int(q.size()-del.size()); } | |
bool empty() const { return !size(); } | |
void flush() { while(del.size() && q.top()==del.top()) q.pop(), del.pop(); } | |
void insert(const T x) { q.push(x); flush(); } | |
void pop() { q.pop(); flush(); } | |
void erase(const T x) { del.push(x); flush(); } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment