# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
267991 | stefantaga | medians (balkan11_medians) | C++14 | 83 ms | 3576 KiB |
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 DIM 200005
using namespace std;
int n,i,p,u;
int v[DIM],frec[DIM],sol[DIM];
int main()
{
cin>>n;
for(i=1; i<=n; i++)
{
cin>>v[i];
}
sol[1]=v[1];
frec[v[1]]=1;
p=1;
u=2*n-1;
for(i=2; i<=n; i++)
{
while(frec[p]==1)
{
p++;
}
while(frec[u]==1)
{
u--;
}
if(v[i]==v[i-1])
{
sol[2*i-2]=p;
sol[2*i-1]=u;
frec[p]=frec[u]=1;
}
else
{
if(frec[v[i]]==0)
{
sol[2*i-2]=v[i];
frec[v[i]]=1;
if(v[i]>v[i-1])
{
sol[2*i-1]=u;
frec[u]=1;
}
else
{
sol[2*i-1]=p;
frec[p]=1;
}
}
else
{
if(v[i]>v[i-1])
{
sol[2*i-2]=u;
frec[u]=1;
while(frec[u]==1)
{
u--;
}
sol[2*i-1]=u;
frec[u]=1;
}
else
{
sol[2*i-2]=p;
frec[p]=1;
while(frec[p]==1)
{
p++;
}
sol[2*i-1]=p;
frec[p]=1;
}
}
}
}
for(i=1; 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... |