#include<iostream>
using namespace std;
int st,dr,Viz[100005],Rez[200005],A[100005];
void addmn(int poz)
{
while(Viz[st])
st++;
Rez[poz]=st;
Viz[st]=1;
}
void addmx(int poz)
{
while(Viz[dr])
dr--;
Rez[poz]=dr;
Viz[dr]=1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1; i<=n; i++)
cin>>A[i];
Rez[1]=A[1];
Viz[A[1]]=1;
st=1;
dr=2*n-1;
for(int i=2; i<=n; i++)
{
if(A[i]==A[i-1])
{
addmn(2*i-2);
addmx(2*i-1);
}
else if(A[i]>A[i-1])
{
if(!Viz[A[i]])
{
Rez[2*i-2]=A[i];
Viz[A[i]]=1;
addmx(2*i-1);
}
else
{
addmx(2*i-2);
addmx(2*i-1);
}
}
else
{
if(!Viz[A[i]])
{
Rez[2*i-2]=A[i];
Viz[A[i]]=1;
addmn(2*i-1);
}
else
{
addmn(2*i-2);
addmn(2*i-1);
}
}
}
for(int i=1; i<=2*n-1; i++)
cout<<Rez[i]<<" ";
cout<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
380 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
504 KB |
Output is correct |
3 |
Correct |
7 ms |
632 KB |
Output is correct |
4 |
Correct |
11 ms |
888 KB |
Output is correct |
5 |
Correct |
15 ms |
1400 KB |
Output is correct |
6 |
Runtime error |
13 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
17 ms |
1272 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |