Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct queue_min {
- vec<pair<int, int>> s1, s2;
- int getmin() {
- if (s1.empty() || s2.empty())
- return s1.empty() ? s2.back().second : s1.back().second;
- else
- return min(s1.back().second, s2.back().second);
- }
- void push(int x) {
- int minima = s1.empty() ? x : min(x, s1.back().second);
- s1.push_back(make_pair(x, minima));
- }
- void pop() {
- if (s2.empty())
- while (!s1.empty()) {
- int element = s1.back().first;
- s1.pop_back();
- int minima = s2.empty() ? element : min(element, s2.back().second);
- s2.push_back({ element, minima });
- }
- //result = s2.top().first;
- s2.pop_back();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment