hdu2429Ping pong
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?
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).
integer, the total number of different games.
3 1 2 3
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath> using namespace std; int an[];
int s[];
const int N = ;
int lb(int x)
{
return x&(-x);
}
void add(int i)
{
if(i>N) return;
s[i]++;
add(i+lb(i));
}
int get(int i)
{
if(i == )return ;
return s[i]+get(i-lb(i));
}
int taa[],tab[],tba[],tbb[]; int main()
{
int z;
cin>>z;
while(z--)
{
int n,i,j,k;
cin>>n;
memset(s,,sizeof(s));
memset(taa,,sizeof(taa));
memset(tab,,sizeof(tab));
for(i = ;i<=n;i++)
scanf("%d",&an[i]);
for(i = ;i<=n;i++)
{
taa[i] = get(an[i]-);
tab[i] = i--get(an[i]);
add(an[i]);
}
memset(s,,sizeof(s));
memset(tba,,sizeof(tba));
memset(tbb,,sizeof(tbb));
for(i = n;i>=;i--)
{
tba[i] = get(an[i]-);
tbb[i] = n-i-get(an[i]);
add(an[i]);
}
long long ans = ;
for(i = ;i<=n;i++)
{
ans += taa[i]*tbb[i]+tab[i]*tba[i];
ans += (i--taa[i]-tab[i])*(n-i)+(taa[i]+tab[i])*(n-i-tba[i]-tbb[i]);
}
cout<<ans<<endl;
}
return ;
}
hdu2429Ping pong的更多相关文章
- HDU 2492 Ping pong (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Problem Description N(3<=N<=2000 ...
- POJ3928Ping pong[树状数组 仿逆序对]
Ping pong Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3109 Accepted: 1148 Descrip ...
- UVALive 4329 Ping pong
Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Fo ...
- Mini projects #4 ---- Pong
课程全名:An Introduction to Interactive Programming in Python,来自 Rice University 授课教授:Joe Warren, Scott ...
- POJ 3928 Ping pong(树状数组)
Ping pong Time Limit: 1000MS ...
- (转) Deep Reinforcement Learning: Pong from Pixels
Andrej Karpathy blog About Hacker's guide to Neural Networks Deep Reinforcement Learning: Pong from ...
- LA4329 Ping pong(树状数组与组合原理)
N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...
- Ping pong
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- POJ 3928 Ping pong
题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...
随机推荐
- T-SQL 函数概述
T-SQL函数的类别和描述: 函数类别 作用 聚合函数 返回一个标量值,表示在某个值域上的聚合,应用于特定的聚合选择或者汇总 配置变量 返回SQL Server执行环境的信息.这些信息可用于给对象编程 ...
- build opencv with python support
cmake -DPYTHON_LIBRARY=/opt/anaconda/lib/libpython2.7.so -DPYTHON_INCLUDE_DIR=/opt/anaconda/include/ ...
- 关于"zoom“ 的一点小认识
最早接触zoom是在清除浮动的时候,原因就是zoom能触发IE的haslayout,当时也没深究其原理,今天,在查看张鑫旭的对overflow与zoom”清除浮动”的一些认识时,其中提到zoom是比例 ...
- JQuery easyui (2)Droppable(放置)组件
所谓放置,就是将一个物体放入一个物体内,当然对于easyui来说触发各种效果是必不可少的,同时这个组件也不会依赖于其他组件. Droppable的加载方式 1,class 加载 一直不太喜欢cl ...
- 淘管 ERP项目与淘宝对接中产生的若干问题及处理办法
现象:ERP绑定淘宝后,下载商品数据时如果成功,ajax不断尝试重发. 原因: /app/taoapi/lib/top/TopClient.php 中的curl()方法成功后,返回空值,而前端收到空 ...
- 【Ecstore】为自建模块添加自定义主题模板
做好ECSOTRE模块后,需在主题中添加模板,而添加模板页面时只有产品分类页.产品详细页.首页等内置模块的模板类型. 下面介绍如何添加一个自定义的模板类型“buildings”. 一.修改(建议复制到 ...
- The kth great number(优先队列)
The kth great number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Oth ...
- connectionStrings基本配置
常用connectionStrings配置: <connectionStrings> <add name="LocalSqlServer" ...
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
原文: https://my.oschina.net/qczhang/blog/190215?p=1
- android继续学习相关
最近不是很忙,但是慢慢就忘记了学习. 我总是选中了一条路后,怀疑它的正确性.我也知道这不好. 一年前,我买了一个ipad,然后玩app上的游戏,觉得很好玩,而且上面很多都是收费的, 当时就觉得,为什么 ...