hdu 2492 Realtime Status

原创 2015年11月19日 20:23:29

Ping pong

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


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
 
题目大意:每人都有一个实力值,顺序就是他的位置。要求找一个对手,然后再找一个裁判,要求裁判的实力再他们之间,而且位置要在他们两人的中间,这样可以组成一场比赛。问总共可以组织多少场比赛?
#include<iostream>
#include<cstring>
#define Size 100100
using namespace std;
int N,c[Size+10],a[Size+10];
int lowbit(int x){
	return x&(-x);
}
void add(int i,int x){
	while(i<=Size)
	{
		c[i]+=x;
		i+=lowbit(i);
	}
}
int Sum(int i){
	int sum=0;
	while(i>0){
		sum+=c[i];
		i-=lowbit(i);
	}
	return sum;
}
int main()
{
	int t,i,left[Size+10],right[Size+10],left1[Size+10],right1[Size+10];
	long long sum;
	cin>>t;
	while(t--)
	{
		cin>>N;
		memset(c,0,sizeof(c));
		for(i=1;i<=N;i++)
		cin>>a[i];
		for(i=1;i<=N;i++){
			add(a[i],1);
			left[i]=Sum(a[i]-1);
			left1[i]=Sum(Size)-Sum(a[i]);
		}
		memset(c,0,sizeof(c));
		for(i=N;i>=1;i--){
			add(a[i],1);
			right[i]=Sum(a[i]-1);
			right1[i]=Sum(Size)-Sum(a[i]);
		}
		sum=0;
		for(i=1;i<=N;i++)
		sum+=left[i]*right1[i]+left1[i]*right[i];
		cout<<sum<<endl;
	}
	return 0;
}

好坑,错了好多次。。。。。
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

HDU杭电1426-Realtime Status 数独问题

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1426 /**************************** 第一次做数独问题,没做之前觉得就...

hdu2492 (树状数组)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 题目大意:1-n 这n个数字杂乱的排成一排,选出两个人比赛,一个人当裁判,其中裁判的标号要在两...

hdu 2492 ping pongs 好似有点感觉了~~

这次还是想了很久,在床上时突然间想通了,不过写得不是太慢了,写代码总是出现一些低级失误,这雨真有点无语~~~~~ #include #define N 100024 struct node{ ...
  • HZXPH
  • HZXPH
  • 2011年04月25日 02:04
  • 391

hdu 2492 Ping pong

囧啊。。最近很喜欢用“囧”。。。呵呵 随便找个北京赛区的水题,居然就是线段树(树状数组),囧啊。。。 这题是求以一个点为中点,前面比它小后面比它大的对数 以及 前面比它大后面比它小的对数 的和。 ...

POJ 2492 || HDU 1829:A Bug's Life(并查集)

传送门: POJ:点击打开链接 HDU:点击打开链接 A Bug's Life Time Limit: 10000MS   Memory Lim...

HDU 2492 pingpang(树状数组)

问题描述:给出一列数Ai,任选三个上升或下降的数为一组,问可以有这样的多少组。  数据范围:0  分析:我觉得。。打死我也想不出这个用树状数组。。            问题转化成 求每个数左右...

POJ 3928 & hdu 2492 & Uva1428 PingPong 【树状数组】

Ping pong                                                   Time Limit: 2000/1000 MS (Java/Others)  ...

hdu 2492 Ping pong (树状数组)

理解对了了题意的话应该算是道简单的树状数组。 题目要求裁判不能同时低于两个人,或者同时高于两人。就是求一个长度为3的顺序序列。 这样的话对于第i个数ai,我们可以求出左边比ai大的数lmaxi,右...
  • cqlf__
  • cqlf__
  • 2012年09月24日 19:30
  • 510

POJ 2492/hdu 1829 A Bug's Life【带权并查集】

A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 33135   ...

HDU2492 Ping pong 树状数组求逆序数

树状数组求逆序数 转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents Problem Description N(3...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:hdu 2492 Realtime Status
举报原因:
原因补充:

(最多只允许输入30个字)