fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define fr first
  4. #define sc second
  5. #define sz(x) (int) x.size()
  6. #define pb push_back
  7. #define all(x) x.begin(), x.end()
  8.  
  9. using namespace std;
  10. using pii = pair<ll, ll>;
  11. using tii = tuple<ll, ll, ll>;
  12. string printBin(ll m) { string a = ""; for(int i=63; i>=0; i--) { if(m & (1<<i)) {a += '1';} else {a += '0';} } return a; }
  13.  
  14. int main() {
  15. int n;
  16. while(cin >> n) {
  17. queue<int> q;
  18. stack<int> st;
  19. priority_queue<int> pq;
  20.  
  21. bool qq = true, stt = true, pqq = true;
  22.  
  23. for(int i=0; i<n; i++) {
  24. int op, x; cin >> op >> x;
  25.  
  26. if(op == 1) {
  27. q.push(x);
  28. st.push(x);
  29. pq.push(x);
  30. } else {
  31. auto qi = q.front();
  32. q.pop();
  33. qq &= (qi == x);
  34.  
  35. auto si = st.top();
  36. st.pop();
  37. stt &= (x == si);
  38.  
  39. auto pi = pq.top();
  40. pq.pop();
  41. pqq &= (x == pi);
  42. }
  43. }
  44.  
  45. int tot = qq + stt + pqq;
  46. if(tot > 1) cout << "not sure\n";
  47. else if(tot == 0) cout << "impossible\n";
  48. else if(qq) cout << "queue\n";
  49. else if(stt) cout << "stack\n";
  50. else cout << "priority queue\n";
  51. }
  52. }
  53.  
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty