Submission #217684

# Submission time Handle Problem Language Result Execution time Memory
217684 2020-03-30T12:25:10 Z KoalaMuch medians (balkan11_medians) C++14
100 / 100
115 ms 13560 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int f[N];
set< int > s;
int ans[N];
int a[N];
int cur = 1;

void upd(int i)
{
    while(i<N)  ++f[i],i+=i&-i;
}
int get(int i,int ret = 0)
{
    while(i)    ret+=f[i],i-=i&-i;
    return ret;
}
void add(int v)
{
    ans[cur] = v;
    s.erase(s.find(v));
    upd(v+1);
    cur++;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)   scanf("%d",&a[i]);
    for(int i=1;i<2*n;i++)  s.insert(i);
    for(int i=1;i<=n;i++)
    {
        if(s.count(a[i]))    add(a[i]);
        while(get(a[i])!=i-1)   add(*s.begin());
        while(cur-get(a[i]+1)!=i)    add(*(--s.end()));
    }
    for(int i=1;i<2*n;i++)  printf("%d ",ans[i]);
    return 0;
}
/*
13 10 3 8 8 10 10 11 11 10
13 1 10 3 2 8 20 4 19 5 18 6
*/

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
medians.cpp:30:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)   scanf("%d",&a[i]);
                             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 8 ms 896 KB Output is correct
3 Correct 12 ms 1408 KB Output is correct
4 Correct 20 ms 2432 KB Output is correct
5 Correct 39 ms 4600 KB Output is correct
6 Correct 72 ms 8824 KB Output is correct
7 Correct 115 ms 13560 KB Output is correct