链接: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. java文档

    http://www.boyunjian.com/javadoc/com.dyuproject.protostuff/protostuff-me/1.0.5/_/com/dyuproject/prot ...

  2. 使用Monitor调试Unity3D Android程序日志输出(非DDMS和ADB)

    使用Monitor调试Unity3D Android程序日志输出(非DDMS和ADB) http://www.cnblogs.com/mrkelly/p/4015245.html 以往调试Androi ...

  3. $state.go页面不刷新数据

    http://blog.csdn.net/WenJimmy/article/details/51027952 假如进入market/beian/add添加数据,保存提交后回退market/beian列 ...

  4. Android隐藏标题栏和状态栏

    一.隐藏标题栏 //隐藏标题栏 this.requestWindowFeature(Window.FEATURE_NO_TITLE); 二.隐藏状态栏 //隐藏状态栏 this.getWindow() ...

  5. faac编码aac

    // faacode.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <faac.h> #include &l ...

  6. 深度分析Linux下双网卡绑定七种模式 多网卡的7种bond模式原理

    http://blog.csdn.net/abc_ii/article/details/9991845多网卡的7种bond模式原理 Linux网卡绑定mode共有七种(~) bond0.bond1.b ...

  7. iOS_隐藏顶部状态栏方式

    关键词:IOS.UIViewController. Status Bar iOS6和iOS7在隐藏 Status Bar 三种方式比较: Storyboard 界面上选中UIViewControlle ...

  8. JQ引用

    <script type="text/javascript" src="http://files.cnblogs.com/914556495wxkj/jquery- ...

  9. svn上传报Authorization failed错误解决办法

    svn上传文件时没有弹出用户登录界面,而是直接报Authorization failed错误.出现该问题基本都是三个配置文件的问题,下面把这个文件列出来 svnserve.conf配置文件中的 [ge ...

  10. C++实现双缓冲

    首先声明下,这篇资料也是整理别人的资料的基础上,总结来的. 在图形图像处理过程中,双缓冲技术是一种比较常见的技术.窗体在响应WM_PAINT消息时,需要对图像进行绘制处理.如果图像绘制次数过多,重绘过 ...