HDU 2492 BIT/逆序数/排列组合
Ping pong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1143 Accepted Submission(s): 387
Each
player has a unique skill rank. To improve their skill rank, they often
compete with each other. If two players want to compete, they must
choose a referee among other ping pong players and hold the game in the
referee's house. For some reason, the contestants can’t choose a referee
whose skill rank is higher or lower than both of theirs.
The
contestants have to walk to the referee’s house, and because they are
lazy, they want to make their total walking distance no more than the
distance between their houses. Of course all players live in different
houses and the position of their houses are all different. If the
referee or any of the two contestants is different, we call two games
different. Now is the problem: how many different games can be held in
this ping pong street?
integer T(1<=T<=20), indicating the number of test cases, followed
by T lines each of which describes a test case.
Every test case
consists of N + 1 integers. The first integer is N, the number of
players. Then N distinct integers a1, a2 … aN follow, indicating the
skill rank of each player, in the order of west to east. (1 <= ai
<= 100000, i = 1 … N).
3 1 2 3
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int sumv[+];
int c[],d[],a[];
int lowbit(int x){return x&-x;}
int sum(int x)
{
int ret=;
while(x){
ret+=sumv[x];
x-=lowbit(x);
}
return ret;
}
void add(int x,int d)
{
while(x<=){
sumv[x]+=d;
x+=lowbit(x);
}
}
int main()
{
int N,t,m,i,j,k;
scanf("%d",&t);
while(t--){memset(sumv,,sizeof(sumv));
LL ans=;
scanf("%d",&N);
for(i=;i<=N;++i){
scanf("%d",&a[i]);
add(a[i],);
c[i]=sum(a[i]-);
}memset(sumv,,sizeof(sumv));
for(i=N;i>=;--i){
add(a[i],);
d[i]=sum(a[i]-);
}
for(i=;i<=N;++i){
ans+=(LL)c[i]*(N-i-d[i])+d[i]*(i--c[i]);
}
printf("%lld\n",ans);
}
return ;
}
HDU 2492 BIT/逆序数/排列组合的更多相关文章
- HDU 5816 状压DP&排列组合
---恢复内容开始--- Hearthstone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java ...
- HDU 1261 字串数(排列组合)
字串数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 【归并排序】【逆序数】HDU 5775 Bubble Sort
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5775 题目大意: 冒泡排序的规则如下,一开始给定1~n的一个排列,求每个数字在排序过程中出现的最远端 ...
- hdu 1394(线段树) 最小逆序数
http://acm.hdu.edu.cn/showproblem.php?pid=1394 给出一列数组,数组里的数都是从0到n-1的,在依次把第一个数放到最后一位的过程中求最小的逆序数 线段树的应 ...
- HDU 1394 Minimum Inversion Number(最小逆序数 线段树)
Minimum Inversion Number [题目链接]Minimum Inversion Number [题目类型]最小逆序数 线段树 &题意: 求一个数列经过n次变换得到的数列其中的 ...
- HDU 4911 (树状数组+逆序数)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4911 题目大意:最多可以交换K次,就最小逆序对数 解题思路: 逆序数定理,当逆序对数大于0时,若ak ...
- HDU 1394 Minimum Inversion Number(线段树/树状数组求逆序数)
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 排列组合+组合数取模 HDU 5894
// 排列组合+组合数取模 HDU 5894 // 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数 // 思路: // 定好m个人 相邻人之间k个座位 剩下就剩n-( ...
- [HDU POJ] 逆序数
HDU 1394 Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...
随机推荐
- oracle 查看隐藏参数
隐藏参数 (hidden parameters) ,由oracle内部使用,以 '_' 开头. 可以通过以下两种方式查看所有隐藏参数: SELECT i.ksppinm name, i.ksppd ...
- Numpy包简单介绍
详细介绍可以看Numpy帮助,也有很多资料,此文仅是一个简述性质的集成文章 1.简介 Numpy是Python的一个扩展包,语法和Matlab有很多相似之处.它支持高维数组和矩阵运算,也提供了许多数组 ...
- HMM、MEMM、CRF模型比较和标注偏置问题(Label Bias Problem)
本文转自:http://www.cnblogs.com/syx-1987/p/4077325.html 路径1-1-1-1的概率:0.4*0.45*0.5=0.09 路径2-2-2-2的概率:0.01 ...
- 格式化字符串函数sprintf
sprintf.snprintf相关函数的主要功能是把格式化的数据写入某个字符串.如最常见的应用是将整数或浮点数转换为字符串. 1.sprintf 将格式化的数据写入字符串,并自动在末尾加上一个空字符 ...
- undefined reference to _imp__xmlFree
Re: [xml] MSYS and MINGW: undefined reference to _imp__xmlFree From: Mike Peat <mpeat unicorninte ...
- vue指令与组件
参考http://blog.csdn.net/lioldamon/article/details/74058222?utm_source=itdadao&utm_medium=referral ...
- PHP开发之环境配置
nignx //start nginx -s reload //restart composer create-project laravel/laravel learnlaravel5 //自动创建 ...
- C#创建类,方法,接口,字段 的 默认类型
1.在namespace中的类.接口默认是internal类型的,也可以显示的定义为public类型2.在一个类里面,属性和方法默认是private的,可以显示的定义为public.private.p ...
- [one day one question] Iscroll 5.0 在chrome上无法滑动
问题描述: Iscroll 5.0 在chrome上无法滑动,不仅仅在chromePC的开发的时候,在手机上的chrome也有同样的问题,这怎么破? 解决方案: // 关闭 PointerEvent ...
- ElasticSearch(六) Elasticsearch在Thinkphp5.0中的使用
首先下载需要引入的类库 链接:https://pan.baidu.com/s/1XEXviLoWM-ypwJ_B0jXqlg 密码:u54t //Elasticsearch.zip类库压缩包地址 然后 ...