题目链接: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的更多相关文章

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

                                                                          Ping pong Time Limit: 1000MS   ...

  2. POJ 3928 Ping pong(树状数组+两次)

    题意:每个人都有一个独特的排名(数字大小)与独特的位置(从前往后一条线上),求满足排名在两者之间并且位置也在两者之间的三元组的个数 思路:单去枚举哪些数字在两者之间只能用O(n^3)时间太高,但是可以 ...

  3. POJ 3928 Ping pong 树状数组模板题

    開始用瓜神说的方法撸了一发线段树.早上没事闲的看了一下树状数组的方法,于是又写了一发树状数组 树状数组: #include <cstdio> #include <cstring> ...

  4. poj3928 Ping pong 树状数组

    http://poj.org/problem?id=3928 Ping pong Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  5. POJ 3928 &amp; HDU 2492 Ping pong(树阵评价倒数)

    主题链接: PKU:http://poj.org/problem?id=3928 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Descript ...

  6. poj Ping pong LA 4329 (树状数组统计数目)

    Ping pong Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2302   Accepted: 879 Descript ...

  7. Frequent values && Ping pong

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

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

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

  9. UVALive 4329 Ping pong

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

随机推荐

  1. RapeLay(电车之狼R)的结局介绍 (隐藏结局攻略)

    RapeLay(电车之狼R)的结局介绍 (隐藏结局) 必备知识要让MM怀孕非常easy.起初刚进入调教模式后.仅仅要H一次 MM就開始有时期状态. 生理(连上有红晕) ->不详状态(闭目第一次) ...

  2. ios开发——实用技术篇OC篇&获取内存使用情况

    获取内存使用情况 iOS 获取 当前设备 可用内存 及当前 应用 所占内存 (-- ::) 转载 ▼ 标签: ios 设备 可用内存 所占内存 内存 it 分类: iOS // 获取当前设备可用内存及 ...

  3. JS原型连

    [推荐]关于JS中的constructor与prototype[转] 最初对js中 object.constructor 的认识: 在学习JS的面向对象过程中,一直对constructor与proto ...

  4. 随机森林实现 MATLAB

    matlab 中随机森林工具箱的下载地址: http://code.google.com/p/randomforest-matlab/downloads/detail?name=Windows-Pre ...

  5. 百度API_Demo

    package com.test.www; import java.io.BufferedReader; import java.io.IOException; import java.io.Inpu ...

  6. 新一代 PHP 加速插件 Zend Opcache

    参考:http://www.laogui.com/Zend-Opcache 大家知道目前PHP的缓存插件一般有三个:APC.eAccelerator.XCache,但未来它们可能都会消失,因为PHP ...

  7. 自定义JPA之AttributeConverter

    1. 执行类 public class BooleanConverter implements AttributeConverter<Boolean, Integer> { } 2. 属性 ...

  8. linux两种增加交换分区(swap)的方法

    在安装Oracle后,为使Oracle流畅运行,需要手动增加linux的交换分区(相当于Windows下的虚拟内存)的大小,本文介绍两种增加交换分区(swap)的方法. 第一种方法:新建分区 1.fd ...

  9. 关于Winform发布时,资源文件缺失的解决方案

    今天和大家分享一下,我这几天一直困惑的问题,今天不经意间解决了这个问题,接下来描述一下这个问题: 问题: 最近公司给人家做二次开发,是C/S结构的,我在做Winform时发现,当我选择一个项目发布时, ...

  10. CXF(2.7.10) - WSDL2Java generated Client

    以调用 http://www.webxml.com.cn/ 提供的 IpAddressSearchWebService 服务为例. 1. 使用 wsdl2java 工具,根据 wsdl 生成 JAX- ...