链接:https://codeforces.ml/problemset/problem/1227/B
题意:
输入q1~qn ,构造满足题意的p序列:
- q1=p1
- q2=max(p1,p2)
- q3=max(p1,p2,p3)
- ...
- qn=max(p1,p2,…,pn)
题解:具体看代码,很好悟的;
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int num[100005] = { 0 };
int cnt[100005] = { 0 };
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
memset(num, 0, sizeof(num));
memset(cnt, 0, sizeof(cnt));
int key = 0;
for (int i = 1; i <= n; i++)
{
num[i] = i;
}
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (x < i)key = 1;
else
{
swap(num[i], num[x]);
}
}
if (key == 1)cout << -1 << endl;
else
{
for (int i = 1; i <= n; i++)
{
cout << num[i] << " ";
}
cout << endl;
}
}
}
|