Submission #632763

# Submission time Handle Problem Language Result Execution time Memory
632763 2022-08-20T17:59:28 Z MasterTaster medians (balkan11_medians) C++14
100 / 100
103 ms 12964 KB
#include <iostream>
#include <vector>
#include <set>

#define ll long long
#define MAXN 200010
#define pb push_back
#define pii pair<int, int>
#define xx first
#define yy second

using namespace std;

int n, b[MAXN], a[MAXN];
bool bio[MAXN];

int main() {
    cin>>n;

    for (int i=1; i<=n; i++) cin>>b[i];
    a[1]=b[1];
    bio[a[1]]=true;

    set<int> s;
    for (int i=1; i<=2*n-1; i++) if (i!=a[1]) s.insert(i);

    for (int i=2; i<=n; i++)
    {
        if (b[i]>b[i-1])
        {
            if (!bio[b[i]])
            {
                a[2*i-2]=b[i];
                bio[b[i]]=true;
                s.erase(b[i]);
            }
            else
            {
                int x=*(s.rbegin());
                a[2*i-2]=x;
                bio[x]=true;
                s.erase(x);
            }
            int x=*(s.rbegin());
            a[2*i-1]=x;
            bio[x]=true;
            s.erase(x);
        }
        else if (b[i]<b[i-1])
        {
            if (!bio[b[i]])
            {
                a[2*i-2]=b[i];
                bio[b[i]]=true;
                s.erase(b[i]);
            }
            else
            {
                int x=*(s.begin());
                a[2*i-2]=x;
                bio[x]=true;
                s.erase(x);
            }
            int x=*(s.begin());
            a[2*i-1]=x;
            bio[x]=true;
            s.erase(x);
        }
        else
        {
            int x=*(s.begin());
            a[2*i-2]=x;
            bio[x]=true;
            s.erase(x);
            x=*(s.rbegin());
            a[2*i-1]=x;
            bio[x]=true;
            s.erase(x);
        }
    }

    for (int i=1; i<=2*n-1; i++) cout<<a[i]<<" ";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 444 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 7 ms 1204 KB Output is correct
4 Correct 19 ms 2304 KB Output is correct
5 Correct 32 ms 4264 KB Output is correct
6 Correct 67 ms 8268 KB Output is correct
7 Correct 103 ms 12964 KB Output is correct