Submission #13726

# Submission time Handle Problem Language Result Execution time Memory
13726 2015-03-28T15:20:09 Z gs14004 즐거운 채소 기르기 (JOI14_growing) C++14
45 / 100
59 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);
    int 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("%d",ret);
}
# 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 1 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 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 21 ms 5772 KB Output is correct
2 Correct 44 ms 5772 KB Output is correct
3 Incorrect 59 ms 5772 KB Output isn't correct
4 Halted 0 ms 0 KB -