POJ 3928 Ping pong
题目链接:http://poj.org/problem?id=3928
乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判的ID和技能值都在两个选手之间的时候才能进行一场比赛,现在问一共能组织多少场比赛。
参考的其他人的代码,重新敲了一遍。
/*POJ 3928
Ping pong
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; #define N 23000
int c[N],n;
long long int ans; struct Node
{
int id;
int level;
} node[N]; bool cmp(Node a,Node b)
{
return a.level<b.level;
} int lowbit(int x)
{
return x & (-x);
} void update(int i,int val)
{
while(i<=n)
{
c[i]+=val;
i+=lowbit(i);
}
} int sum(int i)
{
int s=;
while(i>)
{
s+=c[i];
i-=lowbit(i);
}
return s;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&node[i].level);
node[i].id=i;
}
sort(node+,node++n,cmp);
memset(c,,sizeof(c));
ans=;
long long l,r;
for(int i=; i<=n; i++)
{
l=sum(node[i].id);
r=sum(n)-l;
ans+=(l*(n-node[i].id-r)+r*(node[i].id--l));
update(node[i].id,);
}
printf("%lld\n",ans);
}
return ;
}
POJ 3928 Ping pong的更多相关文章
- POJ 3928 Ping pong(树状数组)
Ping pong Time Limit: 1000MS ...
- POJ 3928 Ping pong(树状数组+两次)
题意:每个人都有一个独特的排名(数字大小)与独特的位置(从前往后一条线上),求满足排名在两者之间并且位置也在两者之间的三元组的个数 思路:单去枚举哪些数字在两者之间只能用O(n^3)时间太高,但是可以 ...
- POJ 3928 Ping pong 树状数组模板题
開始用瓜神说的方法撸了一发线段树.早上没事闲的看了一下树状数组的方法,于是又写了一发树状数组 树状数组: #include <cstdio> #include <cstring> ...
- poj3928 Ping pong 树状数组
http://poj.org/problem?id=3928 Ping pong Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3928 & HDU 2492 Ping pong(树阵评价倒数)
主题链接: PKU:http://poj.org/problem?id=3928 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Descript ...
- poj Ping pong LA 4329 (树状数组统计数目)
Ping pong Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2302 Accepted: 879 Descript ...
- Frequent values && Ping pong
Frequent values 题意是不同颜色区间首尾相接,询问一个区间内同色区间的最长长度. 网上流行的做法,包括翻出来之前POJ的代码也是RMQ做法,对于序列上的每个数,记录该数向左和向右延续的最 ...
- 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 ...
随机推荐
- springMVC3学习(九)--redirect和forward跳转
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ...
- TreeView1MouseMove
procedure TForm1.TreeView1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var nod ...
- Ruby on Rails Tutorial 第二章 之 toy_app项目搭建
(第一章小结) 第一步:生成项目骨架 $ rails _4.1.6_ new toy_app 第二步:修改Gemfile 第三步:安装gem $ bundle install --without pr ...
- java_线程-锁
package com.demo.test3; import java.util.concurrent.CountDownLatch; /** * @author QQ: 1236897 * */ / ...
- mysql的二级索引
mysql中每个表都有一个聚簇索引(clustered index ),除此之外的表上的每个非聚簇索引都是二级索引,又叫辅助索引(secondary indexes). 以InnoDB来说,每个Inn ...
- How to Setup Replicated LevelDB Persistence in Apache ActiveMQ 5.9--转载
原文地址:https://simplesassim.wordpress.com/2013/11/03/how-to-setup-replicated-leveldb-persistence-in-ap ...
- Http Message Converters with the Spring Framework--转载
原文:http://www.baeldung.com/spring-httpmessageconverter-rest 1. Overview This article describes how t ...
- Lua垃圾收集
Lua使用基于被内置在Lua某些算法的垃圾收集自动内存管理.可以自动内存管理的结果,作为一个开发者: 没有必要担心的对象分配内存. 无需释放他们时,不再需要可将其设置为nil. Lua使用运行不时收集 ...
- python(3)-动态参数实现字符串格式化
s1 = "{0} ===> {1}" s = s1.format('lilei', 'boy') print(s) l = ['lilei', 'boy'] s = s1. ...
- Jquery 全选、反选问题解析
最近工作中,需要使用Jquery实现复选框的全选和反选,本人虽然不是专职撸前端的,但这个小问题感觉也没什么难度,下面直接上代码: <div id="list"> < ...