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 <bits/stdc++.h>
#define maxn 100005
using namespace std;
int n;
bool bio[maxn];
int sol[2*maxn];
int tree[8*maxn];
int najm,najv;
void update(int v,int l,int r,int ind)
{
if(l>r || l>ind || ind>r)return;
tree[v]++;
if(l==r)return;
int mid=(l+r)/2;
update(2*v,l,mid,ind);
update(2*v+1,mid+1,r,ind);
}
int query(int v,int l,int r,int lu,int ru)
{
if(l>r || l>ru || lu>r)return 0;
if(lu<=l && r<=ru)return tree[v];
int mid=(l+r)/2;
return query(2*v,l,mid,lu,ru)+query(2*v+1,mid+1,r,lu,ru);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
najm=1;
najv=2*n-1;
for(int i=1;i<=2*n-1;i++)bio[i]=false;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
int uk=0;if(i!=0)uk=2*i-1;
int man=query(1,1,2*n-1,1,x-1);
int vec=uk-man;
if(!bio[x])
{
sol[2*i]=x;
bio[x]=true;
if(vec>man)
{
while(bio[najm])najm++;
sol[2*i+1]=najm;
bio[najm]=true;
najm++;
}
else{
while(bio[najv])najv--;
sol[2*i+1]=najv;
bio[najv]=true;
najv--;
}
}
else{
for(int j=0;j<2;j++)
{
if(vec>man)
{
while(bio[najm])najm++;
sol[2*i+j]=najm;
bio[najm]=true;
najm++;
}
else{
while(bio[najv])najv--;
sol[2*i+j]=najv;
bio[najv]=true;
najv--;
}
}
}
}
for(int i=0;i<2*n-1;i++)cout<<sol[i]<<" ";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |