#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;
cin>>sol[0];
bio[sol[0]]=true;
for(int i=1;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[uk]=x;
uk++;
bio[x]=true;
update(1,1,2*n-1,x);
if(vec>man)
{
while(bio[najm])najm++;
sol[uk]=najm;
update(1,1,2*n-1,najm);
bio[najm]=true;
najm++;
uk++;
}
else{
while(bio[najv])najv--;
sol[uk]=najv;
update(1,1,2*n-1,najv);
bio[najv]=true;
najv--;
uk++;
}
}
else{
for(int j=0;j<2;j++)
{
if(vec>man)
{
while(bio[najm])najm++;
sol[uk]=najm;
update(1,1,2*n-1,najm);
bio[najm]=true;
najm++;
man++;
uk++;
}
else{
while(bio[najv])najv--;
sol[uk]=najv;
update(1,1,2*n-1,najv);
bio[najv]=true;
najv--;
vec++;
uk++;
}
}
}
}
for(int i=0;i<2*n-1;i++)cout<<sol[i]<<" ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Incorrect |
2 ms |
508 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
508 KB |
Output isn't correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
508 KB |
Output is correct |
7 |
Incorrect |
2 ms |
508 KB |
Output isn't correct |
8 |
Correct |
2 ms |
548 KB |
Output is correct |
9 |
Incorrect |
2 ms |
556 KB |
Output isn't correct |
10 |
Correct |
2 ms |
680 KB |
Output is correct |
11 |
Correct |
3 ms |
680 KB |
Output is correct |
12 |
Incorrect |
2 ms |
680 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
680 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
680 KB |
Output is correct |
2 |
Correct |
5 ms |
852 KB |
Output is correct |
3 |
Correct |
8 ms |
1008 KB |
Output is correct |
4 |
Incorrect |
17 ms |
1268 KB |
Output isn't correct |
5 |
Incorrect |
26 ms |
1780 KB |
Output isn't correct |
6 |
Runtime error |
3 ms |
1780 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
3 ms |
1780 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |