-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathc.cpp
64 lines (61 loc) · 1.09 KB
/
c.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 <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int T, N, A[200000], P[200000], Q[200000], I[200000];
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> T;
while(T--){
eat >> N;
for(int i = 0; i < N; i++){
eat >> A[i];
A[i]--;
}
iota(I, I+N, 0);
sort(I, I+N, [](int a, int b){
return A[a] < A[b];
});
set<int> sp, sq;
for(int i = 0; i < N; i++){
sp.insert(i);
sq.insert(i);
}
bool ok = 1;
for(int _i = 0; _i < N; _i++){
int i = I[_i];
auto it1 = sp.find(A[i]);
if(it1 != sp.end()){
P[i] = *it1;
Q[i] = *sq.begin();
sp.erase(it1);
sq.erase(sq.begin());
}else{
auto it2 = sq.find(A[i]);
if(it2 == sq.end()){
ok = 0;
break;
}
P[i] = *sp.begin();
Q[i] = *it2;
sp.erase(sp.begin());
sq.erase(it2);
}
}
if(ok){
moo << "yES" << endl;
for(int i = 0; i < N; i++){
moo << P[i]+1 << ' ';
}
moo << endl;
for(int i = 0; i < N; i++){
moo << Q[i]+1 << ' ';
}
moo << endl;
}else{
moo << "No" << endl;
}
}
}