枚举中间的人,只要知道在这个人前面的技能值比他小的人数和后面技能值比他小的人数就能计算方案数了,技能值大的可有小的推出。

因此可以利用树状数组,从左到右往树上插点,每个点询问sum(a[i]-1)就是前面的技能值比它小的人数,然后再从右边往左重复一遍就可以算出答案。

#include<bits/stdc++.h>
using namespace std; const int maxa = 1e5+;
#define lowbit(x) (x&-x)
int C[maxa];
int sum(int x)
{
int ret = ;
while(x>){
ret += C[x]; x -= lowbit(x);
}
return ret;
} int r;
//x >0
void add(int x,int d)
{
while(x<=r){
C[x] += d; x += lowbit(x);
}
} const int maxn = 2e4+;
int a[maxn],p[maxn]; int main()
{
//freopen("in.txt","r",stdin);
int T; cin>>T;
while(T--){
int n; scanf("%d",&n);
r = ;
for(int i = ; i < n; i++) {
scanf("%d",a+i); r = max(r,a[i]);
}
fill(C+,C++r,);
for(int i = ; i < n; i++){
p[i] = sum(a[i]-);
add(a[i],);
}
fill(C+,C++r,);
long long ans = ;
for(int i = n-; i >= ; i--){
int q = sum(a[i]-);
ans += (n-i--q)*p[i] + q*(i-p[i]);
add(a[i],);
}
printf("%lld\n",ans);
}
return ;
}

UVALive 4329 Ping pong (BIT)的更多相关文章

  1. UVALive 4329 Ping pong(树状数组)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13895 题意:一条街上住有n个乒乓选手,每个人都有一个技能值,现在 ...

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

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

  3. LA 4329 Ping pong (树状数组)

    题意:从左到右给你n个不同的数值,让你找出三个数值满足中间的数值在两边的数值之间的个数. 析:题意还是比较好理解的,关键是怎么求数量,首先我们分解一下只有两种情况,一个是左边<中间<右边, ...

  4. UVALive 4329 Ping pong

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

  5. ACM-ICPC LA 4329 Ping pong(树状数组)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  6. UVALive - 4329 Ping pong 树状数组

    这题不是一眼题,值得做. 思路: 假设第个选手作为裁判,定义表示在裁判左边的中的能力值小于他的人数,表示裁判右边的中的能力值小于他的人数,那么可以组织场比赛. 那么现在考虑如何求得和数组.根据的定义知 ...

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

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

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

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

  9. HDU 2492 Ping pong(数学+树状数组)(2008 Asia Regional Beijing)

    Description N(3<=N<=20000) ping pong players live along a west-east street(consider the street ...

随机推荐

  1. JDK的windows和Linux版本之下载

    简单说下,Eclipse需要Jdk,MyEclipse有自带的Jdk,除非是版本要求 http://www.oracle.com/technetwork/java/javase/downloads/i ...

  2. HDU - 3001 Travelling(三进制状压dp)

    Travelling After coding so many days,Mr Acmer wants to have a good rest.So travelling is the best ch ...

  3. NSMutableAttributedString及NSMutableParagraphStyle的使用

    一.在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘UILabel的textLayer,有的是用html5实现的,都比较 ...

  4. SqlServer2012——多表连接查询

    1.基本连接 select A.姓名,A.性别,B.班级名,B.家庭住址 From 学生信息 A,班级信息 B where A.所属班级=B.班级编号 --把A表与B表连接起来 2.内连接 --内连接 ...

  5. JS实现页面刷新方法

    下面介绍全页面刷新方法:有时候可能会用到 window.location.reload()刷新当前页面. parent.location.reload()刷新父亲对象(用于框架) opener.loc ...

  6. Unity3d 5.3.5使用sqlite3

    http://blog.csdn.net/glunoy/article/details/52037598 国内讲的乱七八糟,更有故作神秘提供Mono.Data.Sqlite.dll System.Da ...

  7. java实现对字符串和数字的冒泡排序

    public static void sort(Object[] objects){ if(objects instanceof Number[]){ for (int i = 0; i < o ...

  8. SAP屏幕字段常用代码集合

    SAP屏幕字段常用代码集合 ().Screen 设计 TABLES: SSCRFIELDS. PARAMETERS: P_EBLEN LIKE VBRK-EBLEN DEFAULT ' '. PARA ...

  9. 13.Python略有小成(装饰器,递归函数)

    Python(装饰器,递归函数) 一.开放封闭原则 ​ 软件面世时,不可能把所有的功能都设计好,再未来的一两年功能会陆续上线,定期更新迭代,软件之前所用的源代码,函数里面的代码以及函数的调用方式一般不 ...

  10. Glassfish 设置时区

    对于Glassfish domain 或者instance下,某个日志的时区不对,前提是系统时区争取. 可以尝试通过如下命令查看jvm 时区设置 asadmin list-jvm-options 如果 ...