-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.cpp
67 lines (61 loc) · 1.31 KB
/
5.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
65
66
67
//
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define dbg(a) cout << a << " -- DEBUG -- "<< endl;
#define Adbg(a) for(auto e: a){cout << e << ' ';};cout << endl;
#define Mdbg(a) for(auto e: a){cout << e.first << ' ' << e.second;cout << endl;}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 2e5;
int main(){_
// 5 3 4 2 1
// 4 2 3 1 5
// 5 3 4 2 5
int t;cin>>t;
while(t--){
int n;cin>>n;
vector<int> a(n,0),b(n,0),c(n,0);
unordered_map<int,int> vis, bi, ci;
for(int i=0;i<n;++i) cin >> a[i];
int ans = 1;
for(int i=0;i<n;++i){
if(vis[a[i]] == 2){
ans = 0;
break;
}else if(vis[a[i]] == 1){
c[i] = a[i];
ci[c[i]] = i;
}
else{
b[i] = a[i];
bi[b[i]] = i;
}
vis[a[i]]++;
}
int l = 0;
if(!ans || vis[1] > 1) cout << "NO" << endl;
else {
cout << "YES" << endl;
int lv2 = -1;
for(int i=0;i<n;++i){
if(vis[n-i] == 2) {lv2 = i;continue;}
else if(vis[n-i] == 1){
c[bi[n-i]] = n-i;
}else{
b[ci[n-lv2]] = n-i;
c[bi[n-lv2]] = n-i;
}
}
for(auto &e: b) cout << e << ' ';
cout << endl;
for(auto &e: c) cout << e << ' ';
cout << endl;
}
}
exit(0);
}