fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void Update_in(int a[],int x,int n){
  4. int i=0;
  5. for(;i<n;++i){
  6. if(a[i]==x)
  7. break;
  8. }
  9. for(;i<n-1;++i)
  10. a[i]=a[i+1];
  11. }
  12. void Update_s(int a[],int b[],int n){
  13. int i=0;
  14. for(;i<n;++i){
  15. b[i]=a[i];
  16. }
  17. reverse(b, b + n);
  18. }
  19. void Update_q(int a[],int b[],int n){
  20. for(int i=0;i<n;++i)
  21. b[i]=a[i];
  22. }
  23. void Update_pq(int a[],int b[],int n){
  24. int i=0;
  25. for(;i<n;++i)
  26. b[i]=a[i];
  27. sort(b,b+n,greater<int>());
  28.  
  29. }
  30.  
  31.  
  32. int main(){
  33. int n;
  34. int tt=5;
  35. while(scanf("%d",&n)!=EOF){
  36.  
  37. int t,b;
  38. int in[n];
  39. int ou[n];
  40. int s[n];
  41. int pq[n];
  42. int q[n];
  43. for(int i=0;i<n;++i){
  44. s[i]=0;
  45. pq[i]=0;
  46. q[i]=0;
  47. }
  48. bool is_s=true;
  49. bool is_q=true;
  50. bool is_pq=true;
  51. int ix=0;
  52. int ox=0;
  53. for(int i=0;i<n;++i){
  54. scanf("%d %d",&t,&b);
  55. if(t==1){
  56. in[ix++]=b;
  57. }else{
  58. ou[ox++]=b;
  59. Update_s(in,s,ix);
  60. Update_q(in,q,ix);
  61. Update_pq(in,pq,ix);
  62. Update_in(in,ou[ox-1],ix);
  63. if(ou[ox-1]!=s[0])
  64. is_s=false;
  65. if(ou[ox-1]!=q[0])
  66. is_q=false;
  67. if(ou[ox-1]!=pq[0])
  68. is_pq=false;
  69. ix--;
  70. }
  71.  
  72. }
  73. int score=0;
  74. if(is_s)
  75. score++;
  76. if(is_q)
  77. score++;
  78. if(is_pq)
  79. score++;
  80. if(score>1)
  81. puts("not sure");
  82. else if(!score)
  83. puts("impossible");
  84. else {
  85. if(is_s)
  86. puts("stack");
  87. else if (is_q)
  88. puts("queue");
  89. else
  90. puts("priority queue");
  91.  
  92.  
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. }
  102.  
  103.  
  104. return 0;
  105. }
  106.  
Success #stdin #stdout 0s 4548KB
stdin
6
1 1
1 2
1 3
2 1
2 2
2 3
6
1 1
1 2
1 3
2 3
2 2
2 1
2
1 1
2 2
4
1 2
1 1
2 1
2 2
7
1 2
1 5
1 1
1 3
2 5
1 4
2 4
stdout
queue
not sure
impossible
stack
priority queue