Restoring the Permutation
from Codeforces Round #710 (Div. 3)
Time limit:2s
Memory limit:256MB
This topic, the topic is very simple to understand, I learned the stl application
For each test, for the same number, the first prototype will output, the latter will find the smallest among the numbers smaller than it in turn, and the second output will find the largest in turn.
ac code:
#include<iostream>
#include<set>
using namespace std;
int t,n;
int x[200005];
void solve(){
set<int> s;
for(int i = 1;i <= n;++i)
s.insert(i);
for(int i = 1;i <= n;++i)
if(x[i] != x[i - 1])
cout<<x[i]<<" ",s.erase(x[i]);
else
cout<<*s.begin()<<" ",s.erase(s.begin());
cout<<"\n";
for(int i = 1;i <= n;++i)
s.insert(i);
for(int i = 1;i <= n;++i)
if(x[i] != x[i - 1])
cout<<x[i]<<" ",s.erase(x[i]);
else
cout<<*prev(s.lower_bound(x[i]))<<" ",s.erase(*prev(s.lower_bound(x[i])));
cout<<"\n";
}
int main(){
cin>>t;
while(t--){
cin>>n;
for(int i = 1;i <= n;++i)
cin>>x[i];
solve();
}
return 0;
}