-
Notifications
You must be signed in to change notification settings - Fork 2
/
1050.cpp
42 lines (37 loc) · 1.08 KB
/
1050.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
#include <cstdio>
#include <queue>
using namespace std;
int n, m, op, num1, num2;
priority_queue<int, vector<int>, greater<int> > group[300001];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &num1);
group[i].push(num1);
}
for (int opnum = 1; opnum <= m; opnum++) {
scanf("%d", &op);
switch (op) {
case 0:
scanf("%d%d", &num1, &num2);
while(group[num2].size()) {
group[num1].push(group[num2].top());
group[num2].pop();
}
break;
case 1:
scanf("%d", &num1);
if (group[num1].empty()) printf("%d\n", -1);
else {
printf("%d\n", group[num1].top());
group[num1].pop();
}
break;
case 2:
scanf("%d%d", &num1, &num2);
group[num1].push(num2);
break;
}
}
return 0;
}