Skip to content

Instantly share code, notes, and snippets.

@GoBigorGoHome
Created January 3, 2020 12:07
Show Gist options
  • Save GoBigorGoHome/186461dfa66ecdb8ecfd58b8440ae409 to your computer and use it in GitHub Desktop.
Save GoBigorGoHome/186461dfa66ecdb8ecfd58b8440ae409 to your computer and use it in GitHub Desktop.
简陋的单调队列
template<typename T,typename Compare>
class MonoQueue {
private:
deque<pair<T,int>> que;
Compare cmp;
public:
void push(const T& val, int i) {
while (!que.empty() && !cmp(que.back().first, val)) {
que.pop_back();
}
que.emplace_back(val, i);
}
T get(int i) {
while (que.front().second < i) {
que.pop_front();
}
return que.front().first;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment