-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.cpp
More file actions
85 lines (81 loc) · 1.96 KB
/
E.cpp
File metadata and controls
85 lines (81 loc) · 1.96 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<bits/stdc++.h>
using namespace std;
#define allout(v) {for(auto i : v)cout<<i<<' ';cout<<endl;}
vector<int> Min(vector<int> Q) {
set<int> pq;
map<int, int> mp;
for (auto i: Q)
mp[i]++;
for (int i = 1; i <= Q.size(); i++) {
if (mp[i] == 0) {
pq.insert(i);
}
}
vector<int> ans(Q.size());
ans[0] = Q[0];
for (int i = 1; i < ans.size(); i++) {
if (Q[i] == Q[i - 1]) {
ans[i] = *pq.begin();
pq.erase(pq.begin());
} else
ans[i] = Q[i];
}
return ans;
}
vector<int> Max(vector<int> Q) {
//just inputting S,ind,val
int n = Q.size();
vector<int> ans(n);
set<int> S;
map<int, int> Data;
vector<int> ind, val;
for (int i = 0; i < Q.size(); i++) {
int xa = Data.size();
Data[Q[i]] = 1;
if (Data.size() != xa) {
ind.push_back(i);
val.push_back(Q[i]);
}
}
for (int i = 1; i <= n; i++) {
if (Data[i] == 0) {
S.insert(i);
}
}
ind.push_back(n);
val.push_back(n);
for (int i = 0; i < ind.size() - 1; i++) {
ans[ind[i]] = val[i];
}
//input done
//shit starts here :
for (int i = 0; i + 1 < ind.size(); i++) {
for (int j = ind[i] + 1; j < ind[i + 1] && j < n; j++) {
auto s = S.lower_bound(Q[j]);
if (s == S.end()) {
ans[j] = *S.rbegin();
S.erase(*S.rbegin());
continue;
}
s--;
assert(s != S.end());
ans[j] = *s;
S.erase(s);
}
}
return ans;
}
signed main() {
cout.tie(nullptr);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int> Q(n);
for (auto &i: Q)
cin >> i;
allout(Min(Q));
allout(Max(Q));
}
}