Submission #11205

# Submission time Handle Problem Language Result Execution time Memory
11205 2014-11-18T16:27:15 Z gs14004 medians (balkan11_medians) C++
100 / 100
49 ms 2952 KB
#include <cstdio>
 
struct bit{
    int tree[270000], lim;
    void init(int n){
        for(lim = 1; lim <= n; lim <<= 1);
    }
    void add(int x){
        printf("%d ",x);
        while(x <= lim){
            tree[x]++;
            x += x & -x;
        }
    }
    int sum(int x){
        int res = 0;
        while(x){
            res += tree[x];
            x -= x & -x;
        }
        return res;
    }
}bit;
 
int v[200005];
int main(){
    int n,t;
    scanf("%d",&n);
    bit.init(2*n);
    int lo = 1, hi = 2*n-1;
    scanf("%d",&t);
    bit.add(t);
    v[t] = 1;
    for (int i=1; i<n; i++) {
        scanf("%d",&t);
        int cnt = 0;
        if(!v[t]){
            v[t] = 1;
            bit.add(t);
            cnt++;
        }
        while(bit.sum(t) < i+1){
            while(v[lo]) lo++;
            v[lo] = 1;
            bit.add(lo);
            cnt++;
        }
        while(cnt < 2){
            while(v[hi]) hi--;
            v[hi] = 1;
            bit.add(hi);
            cnt++;
        }
    }
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:28:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
medians.cpp:31:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&t);
                   ^
medians.cpp:35:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&t);
                       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2952 KB Output is correct
2 Correct 0 ms 2952 KB Output is correct
3 Correct 0 ms 2952 KB Output is correct
4 Correct 0 ms 2952 KB Output is correct
5 Correct 0 ms 2952 KB Output is correct
6 Correct 0 ms 2952 KB Output is correct
7 Correct 0 ms 2952 KB Output is correct
8 Correct 0 ms 2952 KB Output is correct
9 Correct 0 ms 2952 KB Output is correct
10 Correct 0 ms 2952 KB Output is correct
11 Correct 0 ms 2952 KB Output is correct
12 Correct 0 ms 2952 KB Output is correct
13 Correct 0 ms 2952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2952 KB Output is correct
2 Correct 0 ms 2952 KB Output is correct
3 Correct 3 ms 2952 KB Output is correct
4 Correct 6 ms 2952 KB Output is correct
5 Correct 9 ms 2952 KB Output is correct
6 Correct 23 ms 2952 KB Output is correct
7 Correct 49 ms 2952 KB Output is correct