链接: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. nodejs,node原生服务器搭建实例

    nodejs,node原生服务器搭建实例

  2. iOS开发——UI基础-UIButton、UIImageView、UILabel的选择

    1.UILabel - UILabel的常见属性 @property(nonatomic,copy) NSString *text; 显示的文字 @property(nonatomic,retain) ...

  3. iOS权限管理思路

    iOS权限的分类: 1.功能级权限管理 2.数据级权限管理 权限的获取方式: 通常通过网络获取,会有延迟 使用到权限的场景: 1. 点击发送会员专享魔法表情,  判断是否有发送会员专享魔法表情的权限, ...

  4. BZOJ 2342: [Shoi2011]双倍回文

    Sol Manacher. 非常裸的Manacher啊...为什么有那么多人写Manacher+并查集?Set?Treap?...好神奇... 你只需要在 \(p[i]++\) 的位置加上判断就可以了 ...

  5. apscheduler 排程

    https://apscheduler.readthedocs.org/en/v2.1.2/cronschedule.html 参数 说明 year 4位年 month 月份1-12 day 日:1- ...

  6. STS新建的maven项目报错问题

    STS新建的maven项目报错问题 解决方法:打开pom.xml文件添加 <dependency> <groupId>javax.servlet</groupId> ...

  7. VRRP虚拟路由器冗余协议

    VRRP(VirtualRouterRedundancyProtocol,虚拟路由冗余协议)是一种容错协议.通常,一个网络内的所有主机都设置一条缺省路由,这样,主机发出的目的地址不在本网段的报文将被通 ...

  8. [20160704]Addition program that use JOptionPane for input and output

    //Addition program that use JOptionPane for input and output. import javax.swing.JOptionPane; public ...

  9. css常用效果总结

    1.给input的placeholder设置颜色 .phColor::-webkit-input-placeholder { /* WebKit, Blink, Edge */ color:maroo ...

  10. jquery.cookie中的操作

    http://w3school.com.cn/js/js_cookies.asp jquery.cookie中的操作: jquery.cookie.js是一个基于jquery的插件,点击下载! 创建一 ...