#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n, m;
int num[100005];
int front(int x)
{
return x&(-x);
} int update(int x,int k)
{
while(x<=n)
{
num[x]+=k;
x+=front(x);
}
return 1;
} int sum(int x)
{
int s = 0;
while(x>0)
{
s+=num[x];
x-=front(x);
}
return s;
} int main()
{
int a, b, c;
int cur[5005];
while(scanf("%d",&n)!=EOF)
{
memset(num,0,sizeof(num));
memset(cur,0,sizeof(cur));
b = 0;
for(int i=1;i<=n;i++)
{
scanf("%d",&cur[i]);
cur[i]++;
b+=(i-sum(cur[i])-1);
update(cur[i],1);
}
c = b;
for(int i=1;i<=n;i++)
{
b = b + (n-cur[i] +1 ) - cur[i];
c=b<c?b:c;
}
printf("%d\n",c);
}
return 0;
}

Code From Hdu 1394

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

  1. centos6.5 卸载php
  2. Linux学习之三--scp命令
  3. c/c++ 函数、常量、指针和数组的关系梳理
  4. linux中如何启动和关闭svn
  5. Xcode LaunchImage 载入界面大小设置
  6. checkbox和radio使用
  7. CThreadPool
  8. Java异常 —— java.lang.NoClassDefFoundError
  9. MapReduce阅读
  10. 【转】Error: no `server&#39; JVM at `C:\Program Files\Java\jre6\bin\server\jvm.dll&#39;.解决办法
  11. POJ 2570
  12. 给Sublime Text 2安装CTags插件
  13. 用sed、awk、grep同时匹配多个条件(与模式、或模式)
  14. 经典SQL语句大全(转载)
  15. JS,HTML,CSS
  16. php爬虫入门
  17. react-conponent-secondesElapsed
  18. windows/browser ----&gt; cmd命令/powershell命令/chrome插件vimuim命令
  19. 解决提交按钮在IE浏览器正常在360浏览器不可用
  20. 详解华为云基因容器服务GCS

热门文章

  1. map与set的遍历
  2. C# 常用的dialogresult reset 以及if else 等检查获取客户操作信息的操作方法
  3. How to using x++ code create GL journal[AX2012]
  4. 从客户端检测到有潜在危险的Request.Form 值【转】
  5. Java 第七天 动态代理
  6. LinearRegressionWithRegularization
  7. java的软件包
  8. Java入门到精通——调错篇之解决MyEclipse 输入注册码后:Enter or update your subscription information.问题
  9. Fragment+RadioButton实现点击切换页面效果
  10. core java 7 exception