uva 1428 - Ping pong
树状数组,把他们的技能值作为轴;
首先按照编号从小到大插入值,这样就可以得到,技能值比当前小的人数;
然后按照编号从大到小再插一遍;
代码:
#include<cstdio>
#include<cstring>
#define maxn 20005
using namespace std; int a[maxn],c[];
int l[maxn],r[maxn];
int lowbit(int x){return x&-x;}
void add(int x,int d){while(x<=){c[x]+=d,x+=lowbit(x);}}
int sum(int x)
{
int ret=;
while(x>){ret+=c[x],x-=lowbit(x);}
return ret;
} int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
memset(c,,sizeof c);
memset(l,,sizeof l);
memset(r,,sizeof r);
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
add(a[i],);
l[i]=sum(a[i]-);
}
memset(c,,sizeof c);
for(int i=n;i>=;i--)
{
add(a[i],);
r[i]=sum(a[i]-);
}
long long ans=;
for(int i=;i<=n;i++)
ans+=l[i]*(n-i-r[i])+(i-l[i]-)*r[i];
printf("%lld\n",ans);
}
}
uva 1428 - Ping pong的更多相关文章
- UVA 1428 - Ping pong(树状数组)
UVA 1428 - Ping pong 题目链接 题意:给定一些人,从左到右,每一个人有一个技能值,如今要举办比赛,必须满足位置从左往右3个人.而且技能值从小到大或从大到小,问有几种举办形式 思路: ...
- HDU 2492 Ping pong (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Problem Description N(3<=N<=2000 ...
- UVALive 4329 Ping pong
Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Fo ...
- POJ 3928 Ping pong(树状数组)
Ping pong Time Limit: 1000MS ...
- LA4329 Ping pong(树状数组与组合原理)
N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...
- Ping pong
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- POJ 3928 Ping pong
题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...
- Frequent values && Ping pong
Frequent values 题意是不同颜色区间首尾相接,询问一个区间内同色区间的最长长度. 网上流行的做法,包括翻出来之前POJ的代码也是RMQ做法,对于序列上的每个数,记录该数向左和向右延续的最 ...
- 【暑假】[实用数据结构]UVAlive 4329 Ping pong
UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: % ...
随机推荐
- [Javascript + rxjs] Using the map method with Observable
Like an array, Observable has a map method that allows us to transform a sequence into a new Observa ...
- PMP考试的过与只是
我在一年多时间里參加了三次PMP考试,前两次都失败,直到第三次才成功.怎样对待失败?这是每个人都会遇到的挑战.假设我们能用正确的态度对待临时的失败,那么终于的成功也就不远了.我希望通过本文与大家分享一 ...
- park、unpark、ord 函数使用方法(转)
park,unpark,ord这3个函数,在我们工作中,用到它们的估计不多. 我在最近一个工作中,因为通讯需要用到二进制流,然后接口用php接收.当时在处理时候,查阅不少资料.因为它们使用确实比较少, ...
- hadoop错误org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2
错误: org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2 java.io.IOException: Spill failed 错 ...
- vc++ 最小化到托盘的详细实现
在VC++中,想实现将MFC最小化到系统托盘,需要调用NOTIFYICONDATA类,并注册相应的消息,以下详细讲解如何实现: 1.声明一个NOTIFYICONDATA类,也就是NOTIFYICOND ...
- redis安装与使用
linux: 1.下载redis 下载redis: 可以在redis的官网下载 : http://redis.io/ 也可以去谷歌的code下载: http://code.google.com/p/r ...
- 【转】关于C#接口和抽象类的一些说明
接口和抽象类 1.概念 什么是接口? 接口是包含一组虚方法的抽象类型,其中每一种方法都有其名称.参数和返回值. 接口方法不能包含任何实现,CLR允许接口可以包含事件.属性.索引器. 一个类可以实现多个 ...
- 使用html5兼容低版本浏览器
因为html5 新出的一些语义化的标签,在低版本浏览器下不能识别,举个例子,比如你写了一个 header 标签中,写了一段文本,在低版本浏览器下,肯定是能看到的,但是,那是他是不认识 header标签 ...
- 鼠标移入 移出div div会消失的处理
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 自己做的demo--左连接
下面四张表是数据库中已经有的数据: 第一步: 1.left join左连接,left outer join 左外连接,只是写法不同,相同的概念. 2.左连接查出来的结果是一定包含left关键字左边的表 ...