This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |