# Ping pong

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3518    Accepted Submission(s): 1299

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

2008 Asia Regional Beijing

但是考虑c然后统计出小于c的有多少种可能x,大于c有多少种可能y..

很容易知道结果为x*y....

``` 1 //@coder Gxjun
2 //BIT algorithm
3 #include<stdio.h>
4 #include<string.h>
5 #include<stdlib.h>
6 #define maxn 20000
7 #define val 100000
8 int bb[val+5],aa[maxn];
9 //低位技术
10 int lowbit(int k)
11 {
12     return k&(-k);
13 //    return k&(k&(k-1));
14 //    return k&!(k-1);
15 }
16 void  ope(int x)
17 {
18     while(x<=val)
19     {
20         bb[x]++;
21         x+=lowbit(x);
22     }
23 }
24
25 int sum(int x)
26 {
27     int ans=0;
28     while(x>0)
29     {
30         ans+=bb[x];
31         x-=lowbit(x);
32     }
33     return ans;
34 }
35 int xx[maxn],yy[maxn];
36 int main()
37 {
38     int tt,nn,i;
39     scanf("%d",&tt);
40     while(tt--)
41     {
42         scanf("%d",&nn);
43         for(i=0;i<nn;i++)
44             scanf("%d",&aa[i]);
45      //求小于aa[i] 的个数在aa[0]~~aa[i-1]
46        memset(bb,0,sizeof(bb));
47         for(i=0;i<nn;i++)
48         {
49             xx[i]=sum(aa[i]-1);
50             ope(aa[i]);
51         }
52        memset(bb,0,sizeof(bb));
53         for(i=nn-1; i>=0;i--)
54         {
55           yy[i]=sum(aa[i]-1);
56             ope(aa[i]);
57         }
58         __int64 res=0;
59         for(i=0;i<nn ;i++)
60         {
61             res+=(i-xx[i])*yy[i]+xx[i]*(nn-i-1-yy[i]);
62         }
63         printf("%I64d\n",res);
64     }
65     return 0;
66 }```

0 条评论

• ### HDUOJ----1165Eddy's research II

Eddy's research II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536...

• ### HDUOJ----（1031）Design T-Shirt

Design T-Shirt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327...

• ### poj------2352 Stars（树状数组）

Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30268 ...

• ### 使用模拟近似乘子的深度学习训练（performance）

本文通过仿真提出了如何利用近似乘子提高卷积神经网络(CNNs)的训练性能。与精确乘法器相比，近似乘法器在速度、功率和面积方面具有更好的性能。然而，近似乘数有一个...

• ### Codeforces 626E Simple Skewness(暴力枚举+二分)

E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megab...

• ### 【Codeforces】1213B - Bad Prices

版权声明：本文为博主原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接和本声明。 ...

• ### HDU 3032 Nim or not Nim?(Multi-Nim)

Problem Description Nim is a two-player mathematic game of strategy in which ...

• ### 2017 ACM-ICPC 亚洲区（乌鲁木齐赛区）网络赛- A. Banana

In the forest, there is a Banana Company that provides bananas from different pl...

• ### Angular component的一个例子

官网：https://angular.io/guide/architecture-components

• ### POJ2318 TOYS 判断点与直线位置关系 【计算几何】

Calculate the number of toys that land in each bin of a partitioned toy box.