Mahmoud_Hawara

Untitled

Jul 25th, 2022
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #pragma GCC optimize("-Ofast")
  4. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
  5. #pragma GCC optimize("-ffast-math")
  6. #pragma GCC optimize("-funroll-loops")
  7. #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
  8. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  9. const long long MOD = 1e9 + 7, OO = 1e18;
  10. const double PI = acos(-1);
  11. const int N = 1e6 + 5;
  12. const int dx[4] = {0, 0, 1, -1};
  13. const int dy[4] = {1, -1, 0, 0};
  14.  
  15. // struct cmp
  16. // {
  17. //     bool operator() (pair<long long, long long> a, pair<long long, long long>b)
  18. //     {
  19. //         if (a.first != b.first)return a.first < b.first;
  20. //         return a.second > b.second;
  21. //     }
  22. // };
  23.  
  24. long long n, t, x;
  25.  
  26. int main()
  27. {
  28.     IO
  29.     // set<long long, greater<long long>>s;
  30.     // s.insert(1);
  31.     // s.insert(2);
  32.     // for (auto x : s)cout << x << '\n';
  33.  
  34.     // priority_queue<pair<long long, long long>>pq;
  35.     // // {5, 5}, {5, 6}
  36.     // pq.push({5, 5});
  37.     // pq.push({5, 6});
  38.     // pq.push({4, 4});
  39.     // while (!pq.empty())
  40.     // {
  41.     //     cout << pq.top().first << ' ' << pq.top().second << '\n';
  42.     //     pq.pop();
  43.     // }
  44.     while (cin >> n)
  45.     {
  46.         stack<long long>st;
  47.         queue<long long>q;
  48.         priority_queue<long long>pq;
  49.         long long cnt1 = 0, cnt2 = 0;
  50.         while (n--)
  51.         {
  52.             cin >> t >> x;
  53.             if (t == 1)
  54.             {
  55.                 cnt1++;
  56.                 st.push(x);
  57.                 q.push(x);
  58.                 pq.push(x);
  59.             }  
  60.             else
  61.             {
  62.                 cnt2++;
  63.                 if (st.size() && st.top() == x)st.pop();
  64.                 if (q.size() && q.front() == x)q.pop();
  65.                 if (pq.size() && pq.top() == x)pq.pop();
  66.             }
  67.         }
  68.         long long cnt = 0, ans;
  69.         if (st.size() == cnt1 - cnt2)
  70.         {
  71.             cnt++;
  72.             ans = 1;
  73.         }
  74.         if (q.size() == cnt1 - cnt2)
  75.         {
  76.             cnt++;
  77.             ans = 2;
  78.         }
  79.         if (pq.size() == cnt1 - cnt2)
  80.         {
  81.             cnt++;
  82.             ans = 3;
  83.         }
  84.         if (cnt == 0)cout << "impossible\n";
  85.         else if (cnt > 1)cout << "not sure\n";
  86.         else if (ans == 1)cout << "stack\n";
  87.         else if (ans == 2)cout << "queue\n";
  88.         else cout << "priority queue\n";  
  89.     }
  90.     return 0;
  91. }
  92.  
  93. /*
  94.     fifo
  95.     1 2 3 4 5
  96.     push => O(1);
  97.     pop => O(1);
  98.     front => O(1);
  99.     size
  100.     empty
  101.  
  102.     push
  103.     pop
  104.     top
  105.     size
  106.     empty
  107.  
  108.     4 5 8
  109.     push o(long)
  110.     pop o(log)
  111.     top o(1)
  112.  
  113.  
  114. */
  115.  
Advertisement
Add Comment
Please, Sign In to add comment