-
Notifications
You must be signed in to change notification settings - Fork 0
/
Berpizza
57 lines (56 loc) · 1.14 KB
/
Berpizza
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// const int MOD = 1000000007;
void solve()
{
int n;
cin >> n;
vector<int> vis(n + 1, 0);
priority_queue<pair<int, int>> pq;
queue<int> q;
int t = 1;
int c = n;
while (n--)
{
int x;
cin >> x;
if (x == 1)
{
int y;
cin >> y;
pq.push({y, c - t});
// cout << pq.top().first << " " << pq.top().second << endl;
q.push(t);
t++;
}
else if (x == 2)
{
while (vis[q.front()])
q.pop();
vis[q.front()] = 1;
cout << q.front() << " ";
q.pop();
}
else
{
while (!pq.empty() && vis[c - pq.top().second])
pq.pop();
if (!pq.empty())
{
vis[c - pq.top().second] = 1;
cout << c - pq.top().second << " ";
pq.pop();
}
}
}
}
int main()
{
// fast_io;
// precalc();
// int t = 1;
// cin >> t;
// while (t--)
solve();
}