4
1 2
1 1
2 1
2 2
7
1 2
1 5
1 1
1 3
2 5
1 4
2 4
Sample Output
queue
not sure
impossible
stack
priority queue
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <bitset> #include <algorithm> #include <climits> using namespace std; #define LS 2*i #define RS 2*i+1 #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define N 1000005 #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 struct node { int x; bool operator<(node a)const { return x<a.x; } } a; priority_queue <node> P; queue<node> Q; stack<node> S; int main() { int n,k,x; while(~scanf("%d",&n)) { while(!Q.empty())Q.pop(); while(!S.empty())S.pop(); while(!P.empty())P.pop(); int kp,kq,ks; kp=kq=ks=1; while(n--) { scanf("%d%d",&k,&a.x); if(k==1) { P.push(a); Q.push(a); S.push(a); } else { node r; if(!P.empty()&&kp) { r = P.top(); P.pop(); if(r.x!=a.x) kp=0; } else kp=0; if(!Q.empty()&&kq) { r = Q.front(); Q.pop(); if(r.x!=a.x) kq=0; } else kq = 0; if(!S.empty()&&ks) { r = S.top(); S.pop(); if(r.x!=a.x) ks=0; } else ks = 0; } } if(ks&&!kq&&!kp) puts("stack"); else if(!ks&&kq&&!kp) puts("queue"); else if(!ks&&!kq&&kp) puts("priority queue"); else if(!ks&&!kq&&!kp) puts("impossible"); else puts("not sure"); } return 0; }