-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP11995.cpp
67 lines (62 loc) · 1.34 KB
/
P11995.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <stack>
#include <queue>
#include <set>
typedef std::pair<int,int> Pair;
typedef std::set<Pair> PQ;
typedef std::stack<int> Stack;
typedef std::queue<int> Queue;
int main() {
int n, e, o;
while(std::cin >> n) {
bool canBeQueue = true;
bool canBeStack = true;
bool canBePQ = true;
PQ pq;
Queue q; // push, front, pop.
Stack s;
int size = 0;
for(int i = 0; i < n; ++i) {
std::cin >> o >> e;
if(o == 1) {
if(canBePQ)
pq.insert(Pair(-e,i)); // i ensures uniqueness.
if(canBeQueue)
q.push(e);
if(canBeStack)
s.push(e);
++size;
}
else {
if(size <= 0) {
canBeQueue = canBeStack = canBePQ = false;
continue;
}
--size;
if(canBeQueue) {
canBeQueue = q.front() == e;
q.pop();
}
if(canBeStack) {
canBeStack = s.top() == e;
s.pop();
}
if(canBePQ) {
canBePQ = -e == pq.begin()->first;
pq.erase(pq.begin());
}
}
}
int canBeCount = (canBeQueue?1:0) + (canBeStack?1:0) + (canBePQ?1:0);
if(canBeCount > 1)
std::cout << "not sure" << std::endl;
else if(canBeCount == 0)
std::cout << "impossible" << std::endl;
else if(canBeQueue)
std::cout << "queue" << std::endl;
else if(canBeStack)
std::cout << "stack" << std::endl;
else if(canBePQ)
std::cout << "priority queue" << std::endl;
}
}