# 解析

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e4 + 10;
bool isstack, isque, ispri;
struct Stack {
int top, st[maxn];
void clear() {
memset(st, 0, sizeof(st));
top = 0;
}
int pop() {
if (top == 0) return -1;
return st[top--];
}
void insert(int x) {
st[++top] = x;
}
}s;
priority_queue<int> q;
struct Queue {
void clear() {
memset(que, 0, sizeof(que));
}
void insert(int x) {
que[++tail] = x;
}
int pop() {
if (tail == head) return -1;
}
}qa;

inline void Insert(int x) {
s.insert(x), qa.insert(x), q.push(x);
}

inline void check(int x) {
if (q.size() == 0 || q.top() != x) ispri = false;
if (q.size()) q.pop();
if (qa.pop() != x) isque = false;
if (s.pop() != x) isstack = false;
}

inline void Output() {
int cnt = (int)isstack + (int)ispri + (int)isque;
if (cnt >= 2) {
puts("not sure");
} else if (cnt == 0) {
puts("impossible");
} else {
if (isstack) {
puts("stack");
} else if (ispri) {
puts("priority queue");
} else {
puts("queue");
}
}
}

int main() {
int n;
while (~scanf("%d", &n)) {
s.clear(); qa.clear();
while (q.size() > 0) q.pop();
isstack = ispri = isque = true;
for (int i = 1, opt, x; i <= n; ++ i) {
scanf("%d %d", &opt, &x);
if (opt & 1) {
Insert(x);
} else check(x);
}
Output();
}
}

posted @ 2018-11-27 21:39  AlessandroChen  阅读(166)  评论(0编辑  收藏  举报