Problem Description
N(3<=N<=20000) ping pong players live along a west-east street(consider the street as a line segment).

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?

 
Input
The first line of the input contains an 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).

 
Output
For each test case, output a single line contains an
integer, the total number of different games.
 
Sample Input
1
3 1 2 3
 
Sample Output
1
 
Source

#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的更多相关文章

  1. HDU 2492 Ping pong (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Problem Description N(3<=N<=2000 ...

  2. POJ3928Ping pong[树状数组 仿逆序对]

    Ping pong Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3109   Accepted: 1148 Descrip ...

  3. UVALive 4329 Ping pong

                                      Ping pong Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Fo ...

  4. Mini projects #4 ---- Pong

    课程全名:An Introduction to Interactive Programming in Python,来自 Rice University 授课教授:Joe Warren, Scott ...

  5. POJ 3928 Ping pong(树状数组)

                                                                          Ping pong Time Limit: 1000MS   ...

  6. (转) Deep Reinforcement Learning: Pong from Pixels

    Andrej Karpathy blog About Hacker's guide to Neural Networks Deep Reinforcement Learning: Pong from ...

  7. LA4329 Ping pong(树状数组与组合原理)

    N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...

  8. Ping pong

    Ping pong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. POJ 3928 Ping pong

    题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...

随机推荐

  1. execlp函数使用

    原文:http://blog.sina.com.cn/s/blog_6a1837e901011167.html execlp(从PATH 环境变量中查找文件并执行)   相关函数:   fork,ex ...

  2. C++服务器设计(六):设备连接的生命周期管理

    生命周期介绍 每一个服务器系统的新连接从建立开始时,均会经历多个阶段.比如连接的建立,登录的验证,退出前的资源释放等.同时在具体的消息处理中,还会遇到不可识别的消息事件,或者消息处理时出现数据错误等. ...

  3. Linux系统的组成和内核的组成

    关于linux的组成的宏观认识. 组成图: 内核组成: 一个完整的Linux内核一般由5部分组成,它们分别是内存管理.进程管理.进程间通信.虚拟文件系统和网络接口.

  4. YUI Array 之 indexOf(索引值|搜索)

    YUI原码 YUI indexOfYArray.indexOf = Lang._isNative(Native.indexOf) ? function (array, value, from) { r ...

  5. 使用myfocus制作焦点图

    第一步:引入myfocus基本库和所要使用样式的js和css文件 <script src="js/myfocus-2.0.1.min.js"></script&g ...

  6. CSS3动画之旋转魔方盒

    步骤: 1.大盒子里盛放六个子盒子代表立方体的6个面: 2.子盒子开启3d效果  transform-style:preserve-3d; 3.上下面沿X轴旋转90度,一个上移盒子一半高,一个下移盒子 ...

  7. Ubuntu安装字体的方法

    基本步骤如下: 1. 将要安装的字体放在一个文件夹下,以/home/UsrName/Download/Font为例 2.在终端中输入 sudo cp -r /home/UsrName/Download ...

  8. Roads in the North(POJ 2631 DFS)

    Description Building and maintaining roads among communities in the far North is an expensive busine ...

  9. Effective Java单元测试TestNG - 就是爱Java

    TestNG是另一种单元测试的framework,与JUnit的类似,这次Mix将使用它来撰写测试程序,大部分所引用的class package都一样,只差在JUnit与TestNG的字样,可以直接用 ...

  10. USB系列之七:ASPI介绍及命令测试

    在以前的一篇博文<关于构建DOS下编程平台的总结>中曾经介绍了一种在DOS下驱动U盘的方法,我们大致回顾一下.在config.sys中加入两个驱动程序,就可以驱动U盘:device = a ...