#include<stdio.h>
#include<algorithm>
using namespace std;
int dap,n,tree[600010];
struct data
{
int x,y;
bool operator<(const data&r)const
{
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,s;
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++)
{
s=query(1,1,n,a[i].y);
dap+=min(a[i].y-s-1,(n-a[i].y)-(i-1-s));
update(1,1,n,a[i].y);
}
printf("%d",dap);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5776 KB |
Output is correct |
2 |
Correct |
0 ms |
5776 KB |
Output is correct |
3 |
Correct |
0 ms |
5776 KB |
Output is correct |
4 |
Correct |
0 ms |
5776 KB |
Output is correct |
5 |
Correct |
0 ms |
5776 KB |
Output is correct |
6 |
Correct |
0 ms |
5776 KB |
Output is correct |
7 |
Correct |
0 ms |
5776 KB |
Output is correct |
8 |
Correct |
0 ms |
5776 KB |
Output is correct |
9 |
Correct |
0 ms |
5776 KB |
Output is correct |
10 |
Incorrect |
0 ms |
5776 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5776 KB |
Output is correct |
2 |
Incorrect |
0 ms |
5776 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5776 KB |
Output is correct |
2 |
Incorrect |
0 ms |
5776 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
5776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |