Submission #145488

# Submission time Handle Problem Language Result Execution time Memory
145488 2019-08-20T08:56:37 Z MKopchev medians (balkan11_medians) C++14
100 / 100
150 ms 12828 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e5+42;
int n,inp[nmax];
int output[nmax];

set<int> active;

map<int,int> seen;
int get_front(int now)
{
    set<int>::iterator it=active.lower_bound(now);
    it--;
    int num=*it;
    active.erase(it);
    return num;
}
int get_back(int now)
{
    set<int>::iterator it=active.lower_bound(now);
    int num=*it;
    active.erase(it);
    return num;
}
int main()
{
    scanf("%i",&n);
    for(int i=1;i<=n;i++)
        scanf("%i",&inp[i]);

    for(int i=1;i<=2*n-1;i++)
        active.insert(i);

    output[1]=inp[1];

    for(int i=1;i<n;i++)
    {
        seen[inp[i]]++;
        active.erase(inp[i]);
    }

    for(int i=n-1;i>=1;i--)
    {
        if(inp[i]<inp[i+1])
        {
            output[2*i+1]=get_back(inp[i]);
            output[2*i]=get_back(inp[i]);
        }
        else if(inp[i]>inp[i+1])
        {
            output[2*i+1]=get_front(inp[i]);
            output[2*i]=get_front(inp[i]);
        }
        else
        {
            output[2*i+1]=get_back(inp[i]);
            output[2*i]=get_front(inp[i]);
        }
        seen[inp[i]]--;
        if(seen[inp[i]]==0)
            active.insert(inp[i]);
    }
    for(int i=1;i<=2*n-1;i++)
        printf("%i ",output[i]);
    return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
medians.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&inp[i]);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 252 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 10 ms 1320 KB Output is correct
4 Correct 20 ms 2296 KB Output is correct
5 Correct 42 ms 4220 KB Output is correct
6 Correct 89 ms 8184 KB Output is correct
7 Correct 150 ms 12828 KB Output is correct