hdu 4911Inversion
链接: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的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- Android开发资源推荐第2季
Android CPU监控想法,思路,核心技术和代码 Android App /Task/Stack 总体分析 http://www.eoeandroid.com/thread-161703-1-1. ...
- 关于在android 4.2.2 上运行runlmbench
在剑锋的基础上加一些自己笔记,让自己更懂一些这个流程. 参考:http://www.cnblogs.com/zengjfgit/p/5731655.html runlmbench 是一款在linux ...
- Arlenmbx!!!!
我无限制的以安逸为想法 其实生活的不安逸 我所做的事情和思路到底正不正确? 我失败了? 我做不到? 我尝试做到? 我可以做到! 我能做到 我做到了我已经做到了 难道想法和现实是有区别的吗 有理想只是空 ...
- WPF 中更新界面信息
1.Dispatcher.BeginInvoke int ii = 0; new Thread(new ParameterizedThreadStart((i) => { while (true ...
- poj 3268(spfa)
http://poj.org/problem?id=3268 对于这道题,我想说的就是日了狗了,什么鬼,定义的一个数值的前后顺序不同,一个就TLE,一个就A,还16MS. 感觉人生观都奔溃了,果然,题 ...
- poj 3984
http://poj.org/problem?id=3984 题目很简单,就是简单的BFS吧,主要的难点在于坐标的问题 这个呢,可以反其道而行之,就是你从(1,1)到(5,5),你肯定走过一次 走过一 ...
- pip 安装命令
pip官网文档 https://pip.pypa.io/en/latest/reference/pip.html 若没有将c:\Python27\Scripts加入到path环境变量,可以在c:\Py ...
- python读写文件时中文的转码问题
读写文件都要将中文转为unicode字符. 读文件: u = unicode(s, 'gbk') 这里不能使用encode 写文件: u = encode('utf')
- spinlock原理
[参考] http://www.searchtb.com/2011/06/spinlock%E5%89%96%E6%9E%90%E4%B8%8E%E6%94%B9%E8%BF%9B.html
- poj4052
题意:求一个文章(长度5.1e6)里面出现了多少个指定的模式串.重复出现只记一次.而且如果两个模式串都出现的情况下,一个是另一个的子串,则该子串不算出现过. 分析:AC自动机. 由于子串不算所以加一些 ...