hdu2492 Ping pong

题意:一群乒乓爱好者居住在一条直线上,如果两个人想打比赛需要一个裁判,裁判的 位置 必须在两者之间 ,裁判的能力也必须不大于 参赛者最大的,不小于参赛者最小的

白皮的题解:考虑 第 i 个 为裁判 的情况 如果 左边 比 a[i] 小的 人数 为 c[i],则 有  i-c[i]-1 个人 比 a[i] 大,同样 右边 比 a[i] 小 的人数为 d[i] ,则比a[i]大的人为 n - i - d[i];

则方案 为 d[i]*( i - c[i] - 1 ) + c[i] * (n - i - d[i])

用 x[ a[i] ] 表示 比 a[i] 小的个数,这就涉及到了 树状数组

代码……

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
const double ESP = 10e-;
const int MOD = ;
typedef long long LL;
const int MAXN = + ;
const int MAXA = + ;
int bit[MAXA];
int c[MAXN];
int d[MAXN];
int arr[MAXN]; int sum(int i){
int s = ;
while(i > ){
s += bit[i];
i -= i&-i;
}
return s;
} void add(int i,int x){
while(i < MAXA){
bit[i] += x;
i += i&-i;
}
}
int main(){
// freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
memset(bit,,sizeof(bit));
memset(c,,sizeof(c));
memset(d,,sizeof(d));
for(int i = ;i <= n;i++){
scanf("%d",&arr[i]);
c[i] = sum(arr[i]);
add(arr[i],);
}
memset(bit,,sizeof(bit));
for(int i = n;i > ;i--){
d[i] = sum(arr[i]-);
add(arr[i],);
}
LL ans = ;
for(int i = ;i <= n;i++){
ans += c[i]*(n-i-d[i]) + d[i]*(i-c[i]-);
}
printf("%I64d\n",ans);
}
return ;
}

hdu2492 Ping pong的更多相关文章

  1. HDU 2492 Ping pong (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Problem Description N(3<=N<=2000 ...

  2. UVALive 4329 Ping pong

                                      Ping pong Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Fo ...

  3. POJ 3928 Ping pong(树状数组)

                                                                          Ping pong Time Limit: 1000MS   ...

  4. LA4329 Ping pong(树状数组与组合原理)

    N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...

  5. Ping pong

    Ping pong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. POJ 3928 Ping pong

    题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...

  7. Frequent values && Ping pong

    Frequent values 题意是不同颜色区间首尾相接,询问一个区间内同色区间的最长长度. 网上流行的做法,包括翻出来之前POJ的代码也是RMQ做法,对于序列上的每个数,记录该数向左和向右延续的最 ...

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

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

  9. Ping pong(树状数组经典)

    Ping pong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. js求指定时间的周一和周日

    /*计算指定时间的的周一和周日 return=>{mondy:Date,sundy:Date} parms:{ date:指定时间,如果不指定则取当前时间 } */ function getWe ...

  2. HAMA

    http://hama.apache.org/run_examples.html http://www.binospace.com/ http://57832638.iteye.com/blog/20 ...

  3. asp.net插入sql server 中文乱码问题解决方案

    创建数据库的代码---创建promary表 create table promary ( proID int primary key, proName varchar(50) not null ) 出 ...

  4. POJ3318【随机化算法挺有意思】

    题目链接:http://poj.org/problem?id=3318 http://meizhe143.blog.163.com/blog/static/3893836200710299512136 ...

  5. Android 使用动态载入框架DL进行插件化开发

    如有转载,请声明出处: 时之沙: http://blog.csdn.net/t12x3456    (来自时之沙的csdn博客) 概述: 随着应用的不断迭代.应用的体积不断增大,项目越来越臃肿,冗余添 ...

  6. 使用CAShapeLayer和UIBezierPath画一个自定义半圆弧button

    通常我们使用系统自带的UIButton时,一般都是Rect矩形形式的,或则美工给出一张半圆弧的按钮,如图为一张半圆加三角形的按钮,而此时,如果给按钮添加点击事件时,响应事件依然为矩形区域,不符合我们的 ...

  7. Jquery ajax方法详解

    1.url: 要求为string类型的参数,(默认为当前页面地址)发送请求的地址. 2.type: 要求为String类型的参数,请方式(get/post)默认为get.注意其他HTTP请求方法,例如 ...

  8. 设置outlook自动回复

    当有同事需要出差时,或者不能即时回复邮件时,可用此功能. 下面列出设置步骤: 1.  首先,在桌面新建一个用以保存模板的文件夹,例如:emaii. 2.  新建一封邮件,输入你要自动回复的内容.另存为 ...

  9. 【Hibernate】Illegal attempt to associate a collection with two open sessions

    今天在用Hibernate对对象进行修改操作的时候报了这个错. 之前一直没什么错误,但是今天修改了一下表结构,增加了一个OneToMany的映射. 所以在我获取对象,重新set一个变量之后就报了这个错 ...

  10. poj 1363 Rails in PopPush City &&【求堆栈中合法出栈顺序次数】

    问题如下: 问题 B: Rails 时间限制: Sec 内存限制: MB 提交: 解决: [提交][状态][讨论版] 题目描述 There is a famous railway station in ...