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 <stdio.h>
#include <map>
using namespace std;
int N,D[300030],L[300030],R[300030],B[300030],C;
map<int, int> chk;
int main()
{
scanf ("%d",&N);
for (int i=0;i<N;i++) scanf ("%d",&D[i]), chk[D[i]] = 0;
for (map<int,int>::iterator I = chk.begin(); I != chk.end(); I++) I->second = ++C;
for (int i=0;i<N;i++) D[i] = chk[D[i]];
for (int i=0;i<N;i++){
L[i] = i;
for (int x=D[i];x;x-=x&(-x)) L[i] -= B[x];
for (int x=D[i];x<=C;x+=x&(-x)) B[x]++;
}
for (int i=1;i<=C;i++) B[i] = 0;
for (int i=N-1;i>=0;i--){
R[i] = N-1-i;
for (int x=D[i];x;x-=x&(-x)) R[i] -= B[x];
for (int x=D[i];x<=C;x+=x&(-x)) B[x]++;
}
long long ans = 0;
for (int i=0;i<N;i++) ans += L[i] < R[i] ? L[i] : R[i];
printf ("%lld\n",ans);
return 0;
}
# | 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... |