链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911

题意:给定一个序列和k,求在k次交换之后序列的逆序数,只能相邻两个数交换且只有左边的数大于右边时才能交换

代码如下

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<vector>
#include<queue>
#include<iterator>
#include<vector>
#include<set>
#define dinf 0x3f3f3f3f
typedef long long ll;
//const int Max=(1<<16)+10;
using namespace std;
#define SIZE 100000005 ll a[],s[],ans,k; ll merge(int l1,int r1,int l2,int r2)
{
ans=0l;
int i,j,k;
for(i=l1;i<=r2;i++)
s[i]=a[i]; i=l1;j=l2;k=l1;
while(i<=r1 && j<=r2)
{
if(s[i]<=s[j])
a[k++]=s[i++];
else
{
a[k++]=s[j++];
ans+=(r1-i+);
}
}
while(i<=r1)
a[k++]=s[i++];
while(j<=r2)
a[k++]=s[j++];
return ans;
} ll merge_s(int l,int r)
{
ll ans=0l;
if(l<r)
{
int mid=(l+r)/;
ans+=merge_s(l,mid);
ans+=merge_s(mid+,r);
ans+=merge(l,mid,mid+,r);
}
return ans;
} int main()
{
int n;
while(~scanf("%d %lld",&n,&k))
{
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
ans=merge_s(,n);
if(k>=ans)
printf("0\n");
else
printf("%lld\n",ans-k);
}
return ;
}

hdu 4911Inversion的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. 全架构PaaS TAE 2.0的Docker实践

    推荐链接: http://www.infoq.com/cn/news/2015/07/paas-tae-docker

  2. JVM内存监控工具 Jconsole

    -------------Jconsole监视远程的linux服务器上的tomcat ----------------------------- 1.linux服务器上的tomcat 的bin/cat ...

  3. NSTimer用法,暂停,继续,初始化

    NSTimer用法,暂停,继续,初始化 转载:http://blog.csdn.net/zhuzhihai1988/article/details/7742881 NSTimer的使用方法 1.初始化 ...

  4. OpenCV摄像头人脸识别

    注: 从外设摄像装置中获取图像帧,把每帧的图片与人脸特征进行匹配,用方框框住识别出来的人脸 需要用到的函数: CvHaarClassifierCascade* cvLoadHaarClassifier ...

  5. php preg_库正则匹配

    <?php //preg_库提供的正则 preg_match();//进行正则表达式匹配 /* preg_match (pattern , subject, matches) 参数 描述 pat ...

  6. mysql 查询某个日期时间段,每天同一时间段的数据

    mysql 查询某个日期时间段,每天同一时间段的数据: SELECT * FROM t_a01_eltable WHERE DATE_FORMAT(acqtime,'%Y-%m-%d')>='2 ...

  7. Qt5 托盘模仿qq闪烁,弹消息框实现

    在别人代码基础上做的,课设刚好用上了,贴出来分享Qt5.5.1实现. 图片自己找. #ifndef DIALOG_H #define DIALOG_H #include <QDialog> ...

  8. 正在使用广告标识符 (IDFA)

    APP提交审核后,apple方面一直说我使用了IDFA,APP里没有集合任何广告SDK. 怀疑是其他第三方的SDK用了. 检测命令 //在项目的根目录下用终端执行 grep -r advertisin ...

  9. phpcms get标签用法

    {pc:get sql="SELECT t.*,n.*,n.typeid nt FROM v9_type t LEFT JOIN v9_news n ON n.typeid=t.typeid ...

  10. PHP: How to print a debug log?

    file_put_contents('php://stderr', print_r("hello ", TRUE)); 转自: http://stackoverflow.com/q ...