Ping pong
Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

Description

 

N(3N20000) 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(1T20) , 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 a1a2...aN follow, indicating the skill rank of each player, in the order of west to east ( 1ai100000 , 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

Beijing 2008-2009

枚举裁判的位置+树状数组

 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxn=; int tree[maxn+],n; inline int lowbit(int x) {return x&(-x);} void Init()
{
memset(tree,,sizeof(tree));
} int Add(int x)
{
while(x<=maxn)
{
tree[x]++;
x+=lowbit(x);
}
} int getSum(int x)
{
int sum=;
while(x>)
{
sum+=tree[x];
x-=lowbit(x);
}
return sum;
} struct node
{
int leftbig,leftsmall;
int rightbig,rightsmall;
}ND[]; int bilib[]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long int ans=;
scanf("%d",&n);
int x;
for(int i=;i<=n;i++)
{
scanf("%d",&bilib[i]);
}
Init();
for(int i=;i<=n;i++)
{
ND[i].leftsmall=getSum(bilib[i]);
Add(bilib[i]);
ND[i].leftbig=i--ND[i].leftsmall;
}
Init();
for(int i=n;i>=;i--)
{
ND[i].rightsmall=getSum(bilib[i]);
Add(bilib[i]);
ND[i].rightbig=n-i-ND[i].rightsmall;
}
///debug/*
//for(int i=1;i<=n;i++)
//{
// cout<<ND[i].leftsmall<<" , "<<ND[i].leftbig<<endl;
// cout<<ND[i].rightsmall<<" , "<<ND[i].rightbig<<endl;
// cout<<endl;
//}
///.....*/
for(int i=;i<=n-;i++)
{
ans+=1LL*((ND[i].leftsmall*ND[i].rightbig)+(ND[i].leftbig*ND[i].rightsmall));
}
cout<<ans<<endl;
}
return ;
}

UVALive 4329 Ping pong的更多相关文章

  1. 【暑假】[实用数据结构]UVAlive 4329 Ping pong

    UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: % ...

  2. UVALive 4329 Ping pong(树状数组)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13895 题意:一条街上住有n个乒乓选手,每个人都有一个技能值,现在 ...

  3. UVALive - 4329 Ping pong 树状数组

    这题不是一眼题,值得做. 思路: 假设第个选手作为裁判,定义表示在裁判左边的中的能力值小于他的人数,表示裁判右边的中的能力值小于他的人数,那么可以组织场比赛. 那么现在考虑如何求得和数组.根据的定义知 ...

  4. UVALive 4329 Ping pong (BIT)

    枚举中间的人,只要知道在这个人前面的技能值比他小的人数和后面技能值比他小的人数就能计算方案数了,技能值大的可有小的推出. 因此可以利用树状数组,从左到右往树上插点,每个点询问sum(a[i]-1)就是 ...

  5. ACM-ICPC LA 4329 Ping pong(树状数组)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  6. LA 4329 Ping pong 树状数组

    对于我这样一名脑残ACMer选手,这道题看了好久好久大概4天,终于知道怎样把它和“树状数组”联系到一块了. 树状数组是什么意思呢?用十个字归纳它:心里有数组,手中有前缀. 为什么要用树状数组?假设你要 ...

  7. BIT LA 4329 Ping pong

    题目传送门 题意:训练指南P197 分析:枚举裁判的位置,用树状数组来得知前面比它小的和大的以及后面比它小的和大的,然后O (n)累加小 * 大 + 大 * 小 就可以了 #include <b ...

  8. LA 4329 Ping pong (树状数组)

    题意:从左到右给你n个不同的数值,让你找出三个数值满足中间的数值在两边的数值之间的个数. 析:题意还是比较好理解的,关键是怎么求数量,首先我们分解一下只有两种情况,一个是左边<中间<右边, ...

  9. LA 4329 Ping pong

    #include <iostream> #include <cstring> #include <cstdio> using namespace std; ; ; ...

随机推荐

  1. Zabbix监控Tengine

    title: Zabbix监控Tengine tags: zabbix,nginx,tengine author: Chinge Yang date: 2016-12-29 --- Zabbix监控T ...

  2. 解决:PADS导入.DXF结构图出现坐标超出范围问题

    现象: 原因: PCB尺寸是有限的,PADS中对于坐标大小有所限制,但AUTO CAD中的坐标却是无限制的. 解决方法: 1.在AUTO中使用M命令,将绘制的结构图移动至原点: 2.在AUTO中使用W ...

  3. FTP协议

    1. FTP协议 什么是FTP呢?FTP 是 TCP/IP 协议组中的协议之一,是英文File Transfer Protocol的缩写. 该协议是Internet文件传送的基础,它由一系列规格说明文 ...

  4. Struts2 JQuery UI常用插件

    一.什么是插件 ①是遵循一定接口规范编写的程序 ②是原有系统平台功能的扩展和补充 ③只能运行在规定的系统平台下,而不能单独运行 注:由于jQuery插件是基于jQuery脚本库的扩展,所以所有jQue ...

  5. .gitignore详解

    今天讲讲Git中非常重要的一个文件――.gitignore. https://git-scm.com/docs/gitignore 首先要强调一点,这个文件的完整文件名就是“.gitignore”,注 ...

  6. CWMP开源代码研究2——easycwmp安装和学习

    声明:本文是对开源程序代码学习和研究,严禁用于商业目的. 如有任何问题,欢迎和我交流.(企鹅号:408797506) 本文所有笔记和代码可以到csdn下载:http://download.csdn.n ...

  7. maven中央仓库访问速度太慢的解决办法

    方法一:修改settings.xml eclipse中集成的maven的settings.xml文件,找了半年也没找到,我们放弃eclipse中的maven,下一个最新的maven,并在eclipse ...

  8. knockoutJS学习笔记02:jsRender模板引擎

    上一篇最后提到了模板,并尝试自己编写一个最简单版本:有些朋友可能用过 jqtmpl,这是一个基于jquery的模板引擎,不过它已经不再更新了,而且据说渲染速度比较慢.这里介绍另外一个模板引擎:jsRe ...

  9. VMware Workstation中网络连接之桥接、NAT和Host-only

    在Windows XP系统中,安装好VMware Workstation虚拟机软件以后,我们可以查看一下"网络连接"窗口: 在窗口中多出了两块网卡: VMware Network ...

  10. 【SQL】Oracle分页查询的三种方法

    [SQL]Oracle分页查询的三种方法 采用伪列 rownum 查询前10条记录 ? 1 2 3 4 5 6 7 8 9 10 11 [sql] select * from t_user t whe ...