Submission #340117

#TimeUsernameProblemLanguageResultExecution timeMemory
340117MilosMilutinovicmedians (balkan11_medians)C++14
10 / 100
38 ms3200 KiB
#include <bits/stdc++.h> using namespace std; const int N=100050; int n,a[N],ans[N],mn,mx; bool was[2*N]; int down(){ while(was[mx])--mx; was[mx]=1; return mx; } int up(){ while(was[mn])++mn; was[mn]=1; return mn; } int main(){ scanf("%i",&n); for(int i=1;i<=n;i++)scanf("%i",&a[i]); ans[1]=a[1]; was[a[1]]=1; mn=0,mx=2*n; was[0]=1,was[2*n]=1; for(int i=2;i<=n;i++){ if(a[i]==a[i-1]){ ans[2*i-2]=down(); ans[2*i-1]=up(); }else{ if(a[i]>a[i-1]){ if(was[a[i]]){ ans[2*i-2]=down(); ans[2*i-1]=down(); }else{ ans[2*i-2]=a[i]; ans[2*i-1]=down(); } }else{ if(was[a[i]]){ ans[2*i-2]=up(); ans[2*i-1]=up(); }else{ ans[2*i-2]=a[i]; ans[2*i-1]=up(); } } } } for(int i=1;i<=2*n-1;i++)printf("%i ",ans[i]); return 0; }

Compilation message (stderr)

medians.cpp: In function 'int main()':
medians.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |     scanf("%i",&n);
      |     ~~~~~^~~~~~~~~
medians.cpp:18:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     for(int i=1;i<=n;i++)scanf("%i",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...