This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <set>
using namespace std;
set<int> se;
int a[200005];
int b[100005];
int main()
{
int n,cnt=1;
cin>>n;
for(int i=1;i<=n;i++){
cin>>b[i];
}
for(int i=1;i<=2*n-1;i++){
se.insert(i);
}
a[1]=b[1];
se.erase(a[1]);
set<int>::iterator it;
for(int i=2;i<=n;i++){
if(b[i]==b[i-1]){
///trebuie bagate doua elemente, unu mai mare ca b[i],unu mai mic ca b[i]
///le bagam pe cel mai mare si cel mai mic element nefolosit
//cout<<"intra in prima cu "<<i<<"\n";
it=se.begin();
a[++cnt]=*it;
se.erase(it);
it=se.end();
it--;
a[++cnt]=*it;
se.erase(it);
}
else
if(b[i]>b[i-1]){
if(se.count(b[i])==0){
it=se.end();
it--;
a[++cnt]=*it;
se.erase(it);
it=se.end();
it--;
a[++cnt]=*it;
se.erase(it);
///exista deja mijlocul
}
else{
se.erase(b[i]);
a[++cnt]=b[i];
it=se.end();
it--;
a[++cnt]=*it;
se.erase(it);
}
}
else{
if(se.count(b[i])==0){
it=se.begin();
a[++cnt]=*it;
se.erase(it);
it=se.begin();
a[++cnt]=*it;
se.erase(it);
}
else{
se.erase(b[i]);
a[++cnt]=b[i];
it=se.begin();
a[++cnt]=*it;
se.erase(it);
}
}
}
for(int i=1;i<=2*n-1;i++)
cout<<a[i]<<" ";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |