Created
January 3, 2020 12:07
-
-
Save GoBigorGoHome/186461dfa66ecdb8ecfd58b8440ae409 to your computer and use it in GitHub Desktop.
简陋的单调队列
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<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