답안 #10687

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
10687 2014-11-03T11:59:33 Z dohyun0324 즐거운 채소 기르기 (JOI14_growing) C++
100 / 100
188 ms 8120 KB
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,tree[1200010];
long long dap;
struct data
{
    int x,y;
    bool operator<(const data&r)const
    {
        if(x==r.x) return y<r.y;
        return x<r.x;
    }
}a[300010];
void update(int k,int x,int y,int p)
{
    if(x>p || y<p) return;
    tree[k]++;
    if(x==y) return;
    update(k*2,x,(x+y)/2,p);
    update(k*2+1,(x+y)/2+1,y,p);
}
int query(int k,int x,int y,int p)
{
    if(x>p) return 0;
    if(y>p) return query(k*2,x,(x+y)/2,p)+query(k*2+1,(x+y)/2+1,y,p);
    return tree[k];
}
int main()
{
    int i,j,s,t=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i].x);
        a[i].y=i;
    }
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)
    {
        if(a[i].x!=a[i+1].x)
        {
            for(j=t+1;j<=i;j++)
            {
                s=query(1,1,n,a[j].y);
                dap+=min(a[j].y-s-1,(n-a[j].y)-(j-1-s)-(i-j));
                update(1,1,n,a[j].y);
            }
            t=i;
        }
    }
    printf("%lld",dap);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8120 KB Output is correct
2 Correct 0 ms 8120 KB Output is correct
3 Correct 0 ms 8120 KB Output is correct
4 Correct 0 ms 8120 KB Output is correct
5 Correct 0 ms 8120 KB Output is correct
6 Correct 0 ms 8120 KB Output is correct
7 Correct 0 ms 8120 KB Output is correct
8 Correct 0 ms 8120 KB Output is correct
9 Correct 0 ms 8120 KB Output is correct
10 Correct 0 ms 8120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8120 KB Output is correct
2 Correct 0 ms 8120 KB Output is correct
3 Correct 0 ms 8120 KB Output is correct
4 Correct 0 ms 8120 KB Output is correct
5 Correct 0 ms 8120 KB Output is correct
6 Correct 0 ms 8120 KB Output is correct
7 Correct 0 ms 8120 KB Output is correct
8 Correct 0 ms 8120 KB Output is correct
9 Correct 0 ms 8120 KB Output is correct
10 Correct 0 ms 8120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8120 KB Output is correct
2 Correct 0 ms 8120 KB Output is correct
3 Correct 0 ms 8120 KB Output is correct
4 Correct 0 ms 8120 KB Output is correct
5 Correct 0 ms 8120 KB Output is correct
6 Correct 0 ms 8120 KB Output is correct
7 Correct 0 ms 8120 KB Output is correct
8 Correct 0 ms 8120 KB Output is correct
9 Correct 0 ms 8120 KB Output is correct
10 Correct 0 ms 8120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 8120 KB Output is correct
2 Correct 64 ms 8120 KB Output is correct
3 Correct 100 ms 8120 KB Output is correct
4 Correct 120 ms 8120 KB Output is correct
5 Correct 120 ms 8120 KB Output is correct
6 Correct 36 ms 8120 KB Output is correct
7 Correct 152 ms 8120 KB Output is correct
8 Correct 172 ms 8120 KB Output is correct
9 Correct 188 ms 8120 KB Output is correct
10 Correct 180 ms 8120 KB Output is correct