2014
01-26

# Ping pong

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?

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).

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).

1
3 1 2 3

1

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <memory.h>
using namespace std;
typedef __int64 ll;
const int maxn=200010;
int tr[maxn];
int n,m,p,q,k,mxn;
struct BIT
{
int lowbit(int x)
{
return x&-x;
}
{
for (int i=x; i<=mxn; i+=lowbit(i))
{
tr[i]+=c;
}
}
ll sum(int x)
{
ll res=0;
for (int i=x; i>0; i-=lowbit(i))
res+=tr[i];
return res;
}
}bit;
int tt;
ll a[maxn],c[maxn];
int dt[maxn];
int main()
{
//    freopen("in.txt","r",stdin);
scanf("%d",&tt);
while(tt--)
{
memset(tr,0,sizeof tr);
scanf("%d",&n);
mxn=0;
for (int i=1; i<=n; i++)
{
scanf("%d",&dt[i]);
mxn=max(mxn,dt[i]);
}
for (int i=1; i<=n; i++)
{
m=dt[i];
a[i]=bit.sum(m);
c[i]=ll(i-a[i]);
}
//        for (int i=1; i<=n; i++)
//        cout<<a[i]<<" "<<c[i]<<endl;
ll ans=0;
ll x1,x2,y1,y2;
for (int i=2; i<n; i++)
{
x1=a[i]-1;
x2=bit.sum(dt[i])-a[i];
y1=(i-a[i]);
y2=n-bit.sum(dt[i])-y1;
//            cout<<x1<<" "<<y2<<" | "<<x1<<" "<<x2<<endl;
ans+=x1*y2;
ans+=y1*x2;
}
printf("%I64d\n",ans);

}
return 0;
}

1. 站长好。我是一个准备创业的互联网小白,我们打算做一个有关国*际*游*学的平台。手上也有了一些境外资源。现阶段的团队现在没有cto.原意出让一些管理股寻找一个靠谱的技术专家做合伙人, 不知道是不是能得到您的帮助。发个帖子或者其他方式。期待您的回应。可以加我微信tianxielemon聊聊。

2. 题本身没错，但是HDOJ放题目的时候，前面有个题目解释了什么是XXX定律。
这里直接放了这个题目，肯定没几个人明白是干啥