Submission #13727

# Submission time Handle Problem Language Result Execution time Memory
13727 2015-03-28T15:20:36 Z gs14004 즐거운 채소 기르기 (JOI14_growing) C++14
100 / 100
132 ms 5772 KB
#include <cstdio>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<int,int> pi;

int n, a[300005];
pi p[300005];

struct bit{
    int tree[300005], lim;
    void init(int n){
        lim = n + 1;
    }
    void add(int x, int v){
        x++;
        while(x <= lim){
            tree[x] += v;
            x += x & -x;
        }
    }
    int sum(int x){
        x++;
        int ret = 0;
        while(x){
            ret += tree[x];
            x -= x & -x;
        }
        return ret;
    }
}bit;

int main(){
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d",&a[i]);
        p[i] = pi(a[i],i);
    }
    sort(p,p+n);
    long long ret = 0;
    bit.init(n);
    for (int i=0; i<n; i++) {
        int e = i;
        while (e < n && p[e].first == p[i].first) e++;
        for (int j=i; j<e; j++) {
            bit.add(p[j].second,1);
        }
        for (int j=i; j<e; j++) {
            int q = p[j].second;
            ret += min(q - bit.sum(q-1),(n - 1 - q) - (bit.sum(n) - bit.sum(q)));
        }
        i = e-1;
    }
    printf("%lld",ret);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5772 KB Output is correct
2 Correct 0 ms 5772 KB Output is correct
3 Correct 0 ms 5772 KB Output is correct
4 Correct 0 ms 5772 KB Output is correct
5 Correct 1 ms 5772 KB Output is correct
6 Correct 0 ms 5772 KB Output is correct
7 Correct 0 ms 5772 KB Output is correct
8 Correct 0 ms 5772 KB Output is correct
9 Correct 0 ms 5772 KB Output is correct
10 Correct 0 ms 5772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5772 KB Output is correct
2 Correct 0 ms 5772 KB Output is correct
3 Correct 0 ms 5772 KB Output is correct
4 Correct 0 ms 5772 KB Output is correct
5 Correct 0 ms 5772 KB Output is correct
6 Correct 0 ms 5772 KB Output is correct
7 Correct 0 ms 5772 KB Output is correct
8 Correct 0 ms 5772 KB Output is correct
9 Correct 0 ms 5772 KB Output is correct
10 Correct 0 ms 5772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5772 KB Output is correct
2 Correct 0 ms 5772 KB Output is correct
3 Correct 2 ms 5772 KB Output is correct
4 Correct 2 ms 5772 KB Output is correct
5 Correct 0 ms 5772 KB Output is correct
6 Correct 2 ms 5772 KB Output is correct
7 Correct 2 ms 5772 KB Output is correct
8 Correct 0 ms 5772 KB Output is correct
9 Correct 3 ms 5772 KB Output is correct
10 Correct 0 ms 5772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5772 KB Output is correct
2 Correct 42 ms 5772 KB Output is correct
3 Correct 57 ms 5772 KB Output is correct
4 Correct 79 ms 5772 KB Output is correct
5 Correct 65 ms 5772 KB Output is correct
6 Correct 28 ms 5772 KB Output is correct
7 Correct 75 ms 5772 KB Output is correct
8 Correct 132 ms 5772 KB Output is correct
9 Correct 128 ms 5772 KB Output is correct
10 Correct 108 ms 5772 KB Output is correct