-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeTON8_B.cpp
64 lines (50 loc) · 1.05 KB
/
codeTON8_B.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
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define mll long long
#define vl vector<long long>
#define pb push_back
#define forl(i, a, b, c) for (mll i = a; i < b; i += c)
void show(vector<long long> &arr) {
for (mll i = 0; i < arr.size(); ++i) {
cout << arr[i] << " ";
}
cout << endl;
}
void constructPermutation(vector<long long> &a) {
mll n = a.size();
mll m = 0;
map<mll, mll> mp, used;
forl(i, 0, n, 1) mp[i]++;
vector<long long> ans;
for (mll i : a) {
if (mp[m - i]) {
ans.pb(m - i);
used[m - i]++;
mp[m - i] = 0;
} else {
ans.pb(m);
used[m]++;
mp[m] = 0;
}
while (used[m])
m++;
}
show(ans);
}
int main() {
mll t;
cin >> t;
while (t--) {
mll n;
cin >> n;
vector<long long> a(n);
for (mll i = 0; i < n; ++i) {
cin >> a[i];
}
constructPermutation(a);
}
return 0;
}