Problem - D - Codeforces
题意:
思路:
Code:
#include <bits/stdc++.h>
using i64 = long long;
const int N = 1e6 + 10;
int ans[N];
void solve() {
int n;
std::cin >> n;
std::vector<std::pair<int,int> > a(n + 1);
for (int i = 1; i <= n; i ++) {
std::cin >> a[i].first;
a[i].second = i;
}
std::sort(a.begin() + 1, a.end());
int l = 1, r = n;
int idx = n;
while(l <= r) {
if (a[l].first == n - r) {
ans[a[l ++].second] = -idx;
}else if (a[r].first == n - l + 1) {
ans[a[r --].second] = idx;
}else {
std::cout << "NO" << "\n";
return;
}
idx --;
}
std::cout << "YES" << "\n";
for (int i = 1; i <= n; i ++) {
std::cout << ans[i] << " \n" [i == n];
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}