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的更多相关文章
- 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: % ...
- Ping pong(树状数组经典)
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- Spring MVC 入门基础
欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入 原文链接:http://java.chinaitlab.com/advance/899129.html 基本上是一个精简版的 ...
- 顺为资本CEO许达来:为什么说中国创业者很幸福?(附PPT)
顺为资本创始合伙人许达来 编者按:许达来,顺为资本创始合伙人及CEO,代表性投资项目包括小米科技.丁香园.一起作业.加一联创.金山软件及兴达国际等. 本文为许达来在新浪创业举办的新创课活动上的内容分享 ...
- poj 3176 Cow Bowling(区间dp)
题目链接:http://poj.org/problem?id=3176 思路分析:基本的DP题目:将每个节点视为一个状态,记为B[i][j], 状态转移方程为 B[i][j] = A[i][j] + ...
- [对话CTO]当当网熊长青:兴趣是成为优秀工程师的第一因素-CSDN.NET
Women Techmaker 北京站 [对话CTO]当当网熊长青:兴趣是成为优秀工程师的第一因素-CSDN.NET [对话CTO]当当网熊长青:兴趣是成为优秀工程师的第一因素 发表于2 ...
- Android Input设备debug技巧
一.驱动层 检查是否有点上报 adb shell getevent -l /dev/input/eventX 检查input设备支持的属性值 adb shell getevent -i /dev/in ...
- 高屋建瓴 cocos2d-x-3.0架构设计 Cocos2d (v.3.0) rendering pipeline roadmap(原文)
Cocos2d (v.3.0) rendering pipeline roadmap Why (the vision) The way currently Cocos2d does rendering ...
- 由zImage生成uImage
一.手动使用mkimage命令 mkimage -A arm -O linux -T kernel -C none -a 30007fc0 -e 30007fc0 -n uImage -d /wo ...
- 机器学习笔记(一)- from Andrew Ng的教学视频
最近算是一段空闲期,不想荒废,记得之前有收藏一个机器学习的链接Andrew Ng的网易公开课,其中的overfiting部分做组会报告时涉及到了,这几天有时间决定把这部课程学完,好歹算是有个粗浅的认识 ...
- application(expand)--easyui
一,效果图. 二,源代码. <!DOCTYPE html><html><head> <meta charset="UTF-8"> & ...
- 使用sqlite保存数据返回主键
/// <summary> /// 返回insert后的主键值 /// </summary> /// <param name="SQLString"& ...