hdu 4911求逆序数

本文介绍了如何利用线段树数据结构和归并排序算法来高效计算序列中的逆序数。逆序数在排序理论中扮演着重要角色,通过线段树可以实现对逆序对的动态查询,而归并排序则可以在排序过程中计算逆序数。这两个技术的结合提供了一种有效的方法来解决这类问题。
摘要由CSDN通过智能技术生成
如果逆序数大于0,存在1<=i<n,使得交换两个数数后逆序数减少1.
所以答案为max{inversion-k,0}.
经典的分治法复杂度为n*log(n).
bobo has a sequence a  1,a  2,…,a  n. He is allowed to swap two  adjacent numbers for no more than k times. 

Find the minimum number of inversions after his swaps. 

Note: The number of inversions is the number of pair (i,j) where 1≤i<j≤n and a  i>a  j.
Input
The input consists of several tests. For each tests: 

The first line contains 2 integers n,k (1≤n≤10  5</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值