• Source
    1. #include<bits/stdc++.h>
    2. #define pii pair<int,int>
    3. #define ff first
    4. #define ss second
    5. #define pb push_back
    6. #define sz 100005
    7. #define sz1 1000005
    8. #define inf 0x3f3f3f3f
    9. #define endl "\n"
    10.  
    11. using namespace std;
    12.  
    13. stack<int>st;
    14.  
    15. queue<int>Q;
    16.  
    17. priority_queue<int>pq;
    18.  
    19. int main()
    20. {
    21. int a,b,c,i,n,countS,countQ,countpq,counter1;
    22.  
    23. while(scanf("%d",&n)!=EOF)
    24. {
    25. countS=countQ=countpq=0;
    26.  
    27. counter1 = 0;
    28.  
    29. for(i=1; i<=n; i++)
    30. {
    31. scanf("%d%d",&a,&b);
    32.  
    33. if(a==2)
    34. {
    35. counter1++;
    36. }
    37. if(a==1)
    38. {
    39. st.push(b);
    40.  
    41. Q.push(b);
    42.  
    43. pq.push(b);
    44. }
    45. else if(st.size()>0 || Q.size()>0 || pq.size()>0)
    46. {
    47.  
    48. if(st.top()==b)
    49. {
    50. countS++;
    51. st.pop();
    52. }
    53. if(Q.front()==b)
    54. {
    55. countQ++;
    56. Q.pop();
    57. }
    58. if(pq.top()==b)
    59. {
    60. countpq++;
    61. pq.pop();
    62. }
    63. }
    64. }
    65.  
    66. int cnt =0,tag,tag1,tag2;
    67.  
    68. tag=tag1=tag2=0;
    69.  
    70. if(countS==counter1)
    71. {
    72. tag=1;
    73. cnt++;
    74. }
    75. if(countQ==counter1)
    76. {
    77. tag1=1;
    78. cnt++;
    79. }
    80. if(countpq==counter1)
    81. {
    82. tag2=1;
    83. cnt++;
    84. }
    85.  
    86. if(cnt>1)
    87. {
    88. printf("not sure\n");
    89. }
    90. else if(cnt==1)
    91. {
    92. if(tag)
    93. {
    94. printf("stack\n");
    95. }
    96. else if(tag1)
    97. {
    98. printf("queue\n");
    99. }
    100. else if(tag2)
    101. {
    102. printf("priority queue\n");
    103. }
    104. }
    105. else
    106. {
    107. printf("impossible\n");
    108. }
    109.  
    110. while(!Q.empty())
    111. {
    112. Q.pop();
    113. }
    114. while(!st.empty())
    115. {
    116. st.pop();
    117. }
    118. while(!pq.empty())
    119. {
    120. pq.pop();
    121. }
    122. }
    123.  
    124. return 0;
    125. }
    126.