这题也不知道怎么证。。叫他直觉题。
凭直觉 应该是怎么做。。?
就是把b数组翻转 。然后把中间部分 转移到 旁边不相等的位置。。
这题主要有一个遍历技巧
🔥a[i] != a[l] && b[i] != a[l] && l <= r 很好的定义了那些可以置换的i位置
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll __int128_t
#define ar array<int, 2>
#define arr array<int, 3>
int n, m, k, inf = 1LL << 61, mod = 998244353;// 1e9+7;
const int N = 5e5 + 50;
void solve() {
cin >> n;
int a[n], b[n];
auto out = [&]() {cout << "Yes\n"; for (int &x : b)cout << x << " "; exit(0);};
for (int &x : a)
cin >> x;
for (int &x : b)
cin >> x;
reverse(b, b + n);
int l = -1, r;
for (int i = 0; i < n; ++i)
if (a[i] == b[i]) {
if (l < 0)
l = i;
r = i;
}
if (l == -1)out();
for (int i = 0; i < n; ++i)
if (a[i] != a[l] && b[i] != a[l] && l <= r) {
swap(b[i], b[l]);
l++;
}
if (l <= r) {
cout << "No";
return ;
}
out();
};
// 正排 逆排。。
// 遍历有个技巧。。
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
#ifdef DEBUG
freopen("../1.in", "r", stdin);
#endif
//init_f();
//init();
//expr();
// int T; cin >> T; while(T--)
solve();
return 0;
}