Submission #85819

# Submission time Handle Problem Language Result Execution time Memory
85819 2018-11-21T16:15:36 Z igzi medians (balkan11_medians) C++17
100 / 100
99 ms 14300 KB
#include <bits/stdc++.h>
#define maxN 100005

using namespace std;

int a[2*maxN],b[maxN],n,i;
set <int> s;
set<int>::iterator it;

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin>>n;
    for(i=0;i<n;i++) cin>>b[i];
    a[0]=b[0];
    for(i=0;i<2*n-1;i++) s.insert(i+1);
    s.erase(a[0]);
    for(i=1;i<n;i++){
       if(b[i]==b[i-1]){
        it=s.begin();
        a[2*i-1]=*it;
        s.erase(it);
        it=s.end();
        it--;
        a[2*i]=*it;
        s.erase(it);
       }
       if(b[i]>b[i-1]){
        it=s.lower_bound(b[i]);
        if(*it==b[i]){
            a[2*i-1]=b[i];
            s.erase(*it);
        }
        else{
            it=s.end();
            it--;
            a[2*i-1]=*it;
            s.erase(it);
        }
        it=s.end();
        it--;
        a[2*i]=*it;
        s.erase(it);
       }
       if(b[i]<b[i-1]){
        it=s.lower_bound(b[i]);
        if(*it==b[i]){
            a[2*i-1]=b[i];
            s.erase(*it);
        }
        else{
            it=s.begin();
            a[2*i-1]=*it;
            s.erase(it);
        }
        it=s.begin();
        a[2*i]=*it;
        s.erase(it);
       }
    }
    for(i=0;i<2*n-1;i++) cout<<a[i]<<" ";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 652 KB Output is correct
4 Correct 2 ms 764 KB Output is correct
5 Correct 2 ms 764 KB Output is correct
6 Correct 2 ms 812 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 2 ms 952 KB Output is correct
9 Correct 2 ms 952 KB Output is correct
10 Correct 2 ms 952 KB Output is correct
11 Correct 2 ms 952 KB Output is correct
12 Correct 2 ms 968 KB Output is correct
13 Correct 3 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1504 KB Output is correct
2 Correct 5 ms 1628 KB Output is correct
3 Correct 8 ms 2068 KB Output is correct
4 Correct 14 ms 3132 KB Output is correct
5 Correct 29 ms 5236 KB Output is correct
6 Correct 62 ms 9448 KB Output is correct
7 Correct 99 ms 14300 KB Output is correct