답안 #10686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
10686 2014-11-03T11:57:13 Z gs13068 즐거운 채소 기르기 (JOI14_growing) C++
0 / 100
12 ms 4604 KB
#include<cstdio>
#include<algorithm>

std::pair<int,int> a[300001];

int BIT[300001];
void upd(int x){while(x<=300000){BIT[x]++;x+=x&-x;}}
int sum(int x){int r=0;while(x){r+=BIT[x];x-=x&-x;}return r;}

int main()
{
	long long r=0;
	int i,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i].first);
		a[i].second=i;
	}
	std::sort(a+1,a+n+1);
	for(i=1;i<=n;i++)
	{
        r+=std::min(a[i].second-sum(a[i].second)-1,n-a[i].second-i+sum(a[i].second)+1);
        upd(a[i].second);
	}
	printf("%lld",r);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4604 KB Output is correct
2 Correct 0 ms 4604 KB Output is correct
3 Correct 0 ms 4604 KB Output is correct
4 Correct 0 ms 4604 KB Output is correct
5 Correct 0 ms 4604 KB Output is correct
6 Correct 0 ms 4604 KB Output is correct
7 Correct 0 ms 4604 KB Output is correct
8 Correct 0 ms 4604 KB Output is correct
9 Correct 0 ms 4604 KB Output is correct
10 Incorrect 0 ms 4604 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4604 KB Output is correct
2 Incorrect 0 ms 4604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4604 KB Output is correct
2 Incorrect 0 ms 4604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 4604 KB Output isn't correct
2 Halted 0 ms 0 KB -