mrlolthe1st

Untitled

Sep 21st, 2021
618
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct queue_min {
  2.     vec<pair<int, int>> s1, s2;
  3.     int getmin() {
  4.         if (s1.empty() || s2.empty())
  5.             return s1.empty() ? s2.back().second : s1.back().second;
  6.         else
  7.             return min(s1.back().second, s2.back().second);
  8.     }
  9.     void push(int x) {
  10.         int minima = s1.empty() ? x : min(x, s1.back().second);
  11.         s1.push_back(make_pair(x, minima));
  12.     }
  13.     void pop() {
  14.         if (s2.empty())
  15.             while (!s1.empty()) {
  16.                 int element = s1.back().first;
  17.                 s1.pop_back();
  18.                 int minima = s2.empty() ? element : min(element, s2.back().second);
  19.                 s2.push_back({ element, minima });
  20.             }
  21.         //result = s2.top().first;
  22.         s2.pop_back();
  23.     }
  24. };
  25.  
  26.  
RAW Paste Data