Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #pragma GCC optimize("-Ofast")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
- #pragma GCC optimize("-ffast-math")
- #pragma GCC optimize("-funroll-loops")
- #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const long long MOD = 1e9 + 7, OO = 1e18;
- const double PI = acos(-1);
- const int N = 1e6 + 5;
- const int dx[4] = {0, 0, 1, -1};
- const int dy[4] = {1, -1, 0, 0};
- // struct cmp
- // {
- // bool operator() (pair<long long, long long> a, pair<long long, long long>b)
- // {
- // if (a.first != b.first)return a.first < b.first;
- // return a.second > b.second;
- // }
- // };
- long long n, t, x;
- int main()
- {
- IO
- // set<long long, greater<long long>>s;
- // s.insert(1);
- // s.insert(2);
- // for (auto x : s)cout << x << '\n';
- // priority_queue<pair<long long, long long>>pq;
- // // {5, 5}, {5, 6}
- // pq.push({5, 5});
- // pq.push({5, 6});
- // pq.push({4, 4});
- // while (!pq.empty())
- // {
- // cout << pq.top().first << ' ' << pq.top().second << '\n';
- // pq.pop();
- // }
- while (cin >> n)
- {
- stack<long long>st;
- queue<long long>q;
- priority_queue<long long>pq;
- long long cnt1 = 0, cnt2 = 0;
- while (n--)
- {
- cin >> t >> x;
- if (t == 1)
- {
- cnt1++;
- st.push(x);
- q.push(x);
- pq.push(x);
- }
- else
- {
- cnt2++;
- if (st.size() && st.top() == x)st.pop();
- if (q.size() && q.front() == x)q.pop();
- if (pq.size() && pq.top() == x)pq.pop();
- }
- }
- long long cnt = 0, ans;
- if (st.size() == cnt1 - cnt2)
- {
- cnt++;
- ans = 1;
- }
- if (q.size() == cnt1 - cnt2)
- {
- cnt++;
- ans = 2;
- }
- if (pq.size() == cnt1 - cnt2)
- {
- cnt++;
- ans = 3;
- }
- if (cnt == 0)cout << "impossible\n";
- else if (cnt > 1)cout << "not sure\n";
- else if (ans == 1)cout << "stack\n";
- else if (ans == 2)cout << "queue\n";
- else cout << "priority queue\n";
- }
- return 0;
- }
- /*
- fifo
- 1 2 3 4 5
- push => O(1);
- pop => O(1);
- front => O(1);
- size
- empty
- push
- pop
- top
- size
- empty
- 4 5 8
- push o(long)
- pop o(log)
- top o(1)
- */
Advertisement
Add Comment
Please, Sign In to add comment