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. Winform开发之窗体传值

    Winform的窗体之间的数据传递是开发的必备技术,下面介绍几种典型的传值方法 1.构造函数传值,但这种方法是单向的(推荐) 上代码,先传值 private void button2_Click(ob ...

  2. Entity Framework Code First主外键关系映射约定

    本篇随笔目录: 1.外键列名默认约定 2.一对多关系 3.一对一关系 4.多对多关系 5.一对多自反关系 6.多对多自反关系 在关系数据库中,不同表之间往往不是全部都单独存在,而是相互存在关联的.两个 ...

  3. C++中的条件传送代码

    条件传送代码-这种代码先计算一个条件操作的两种结果,然后再条件从而选其中一个-条件传送代码匹配了现代处理器的性能特征(因为现代处理器是流水线) void minmax2(int a[],int b[] ...

  4. php中mail()改用msmtp发送邮件

    php中的mail()函数默认调用的是sendmail,这次我将其换成了轻量级的msmtp.在次过程中涉及到:修改配置文件php.ini,创建配置文件msmtprc或(.msmtprc)并修改其权限. ...

  5. struts2注解驱动 零配置

    一.配置web.xml<filter><filter-name>struts2</filter-name><filter-class>org.apach ...

  6. 如何调用EcStore中的API接口

    EcStore系统已内置了丰富的API接口供外部系统调用(接口列表见文章最下面),外部系统具体如何调用这些API呢? 例如有一个PHP的论坛需要调用ecstore系统内一个商品的详情,则可以使用b2c ...

  7. CentOS 6.4 LNMP 环境编译安装

    1.关闭 SELinux 编辑 /etc/selinux/config SELINUX="disabled" 2.安装编译器 yum install gcc gcc-c++ -y ...

  8. 利用7z实现一键解压

    目的: 实现双击zip,7z,rar等文件时自动解压,解压完毕后自动打开文件夹. 工具: [本文末尾附有所有工具的下载地址] 7z.exe types 步骤: 新建"7z-自动解压" ...

  9. Js验证 :只能输入数字和小数点 验证是否是数字 js取float型小数点后两位

    JS判断只能是数字和小数点 1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g,'') ...

  10. SQL Server 索引的图形界面操作 <第十二篇>

    一.索引的图形界面操作 SQL Server非常强大的就是图形界面操作.关于索引方面也一样那么强大,很多操作比如说重建索引啊,查看各种统计信息啊,都能够通过图形界面快速查看和操作,下面来看看SQL S ...