-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathH_Sorting_Queries.cpp
49 lines (46 loc) · 952 Bytes
/
H_Sorting_Queries.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
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <queue>
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using namespace std;
int main()
{
const int add = 1;
const int printAndRemoveFirst = 2;
priority_queue<int, vector<int>, greater<int> > pq;
FastIO;
int n;
cin >> n;
int x, y;
queue<int> q;
while (n--)
{
cin >> x;
if (x == add)
{
cin >> y;
q.push(y);
}
else if (x == printAndRemoveFirst)
{
if (!pq.empty())
{
cout << pq.top() << endl;
pq.pop();
} else {
cout << q.front() << endl;
q.pop();
}
}
else {
while(!q.empty()){
pq.push(q.front());
q.pop();
}
}
}
}