# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39703 | Pajaraja | medians (balkan11_medians) | C++14 | 69 ms | 7872 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>
using namespace std;
bool u[200007],k[200007];
int b[100007],add;
vector<int> ub[100007];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&b[i]);
priority_queue<int> g,l;
//for(int i=0;i<n-1;i++) for(int j=fmin(b[i],b[i+1]);j<fmax(b[i],b[i+1]);j++) k[j]=true;
for(int i=1;i<2*n;i++) if(!k[i])
{
g.push(i);
l.push(-i);
}
u[b[0]]=true;
add=1;
printf("%d ",b[0]);
for(int i=0;i<n-1;i++)
{
if(!u[b[i+1]])
{
u[b[i+1]]=true;
add++;
printf("%d ",b[i+1]);
}
if(b[i]>b[i+1])
{
while(add<2*i+3)
{
int c=-l.top();
l.pop();
if(u[c]) continue;
u[c]=true;
add++;
printf("%d ",c);
}
}
if(b[i]==b[i+1])
{
while(add<2*i+2)
{
int c=-l.top();
l.pop();
if(u[c]) continue;
u[c]=true;
add++;
printf("%d ",c);
}
while(add<2*i+3)
{
int c=g.top();
g.pop();
if(u[c]) continue;
u[c]=true;
add++;
printf("%d ",c);
}
}
if(b[i]<b[i+1])
{
while(add<2*i+3)
{
int c=g.top();
g.pop();
if(u[c]) continue;
u[c]=true;
add++;
printf("%d ",c);
}
}
/*for(int j=fmin(b[i],b[i+1]);j<fmax(b[i],b[i+1]);j++)
{
g.push(j);
l.push(-j);
}*/
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |