题意:
给出一个长度为n的序列a,构造一个长度为2 n的序列b,使得a i = m i n ( b 2 i , b 2 i − 1 )
思路:
可以发现最小值的部分是没有重合的,将a i
直接赋给两者之一即可。
比如假设b 2 i − 1 = a i,那么怎么确定b 2 i呢
找出所有没有被用过的数v,对于每个数a i,二分查找大于a i的最小的数x,这就是b 2 i。
在v中删去x后继续进行下一个。
代码:
// Problem: C. Restoring Permutation // Contest: Codeforces - Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) // URL: https://codeforces.com/contest/1315/problem/C // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #pragma GCC optimize(1) #pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<list> #include<unordered_map> //#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll>PLL; typedef pair<int, int>PII; typedef pair<double, double>PDD; #define I_int ll inline ll read(){ll x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;} inline void write(ll x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');} #define read read() #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define multiCase int T;cin>>T;for(int t=1;t<=T;t++) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i<(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define perr(i,a,b) for(int i=(a);i>(b);i--) ll ksm(ll a, ll b,ll mod){ll res = 1;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;} const int maxn=2e5+100,inf=0x3f3f3f3f; int a[210],b[210]; int main(){ #ifdef LOCAL freopen("in.in","r",stdin); freopen("out.out","w",stdout); #endif int _=read; while(_--){ int n=read,m=2*n; map<int,int>mp; rep(i,1,n) a[i]=read,b[2*i-1]=a[i],mp[a[i]]=1; vector<int>v; rep(i,1,m) if(!mp[i]) v.push_back(i); bool flag=1; rep(i,1,n){ int pos=upper_bound(v.begin(),v.end(),a[i])-v.begin(); if(pos==v.size()){ flag=0;break; } b[2*i]=v[pos]; auto tp=lower_bound(v.begin(),v.end(),b[2*i]); v.erase(tp); } if(!flag) puts("-1"); else{ rep(i,1,m) cout<<b[i]<<" "; puts(""); } } return 0; }