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

因此可以利用树状数组,从左到右往树上插点,每个点询问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. dialog 设置maxHeight 最大高度

    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);Displ ...

  2. 2017 Gartner Hype Cycle for Emerging Technologies: AI, AR/VR, Digital Platforms

  3. cf813C(bfs)

    题目链接:http://codeforces.com/problemset/problem/813/C 题意:给出一颗树,开始时两个人 Alice 和 Bob 分别站在 1(树根)和 x 处.此后每一 ...

  4. 洛谷P1829 [国家集训队]Crash的数字表格 / JZPTAB(莫比乌斯反演)

    传送门 式子好麻烦orz……大佬好腻害orz->这里 //minamoto #include<iostream> #include<cstdio> #define ll ...

  5. nodejs 从helloworld到高质量的后台服务server的一点思考

    ---恢复内容开始--- 新公司用的nodejs作为app和网站的后台服务server,所以最近对nodejs一直在学习,加上之前简单的学习了一点,看了两天后台接口源码,所以就直接上手干活了,下面是我 ...

  6. Posture Energy——姿态的能量

    人的生活是套路化的,人活得越久,被套路化的概率就越大.普通百姓的生活都如同一个模板刻出来的. 一旦生活微调,我们会突然发现原来几十年的认知有问题,如同重获新生的感觉.譬如:早起,当我们每天早起一小时, ...

  7. plsql developer 执行sql 文件

    用 Command Window,执行 @'sql file path' 注意,上面sql文件路径要加单引号

  8. PAT甲级——1104 Sum of Number Segments (数学规律、自动转型)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segmen ...

  9. java模拟多线程

    public class HTTPRequest  implements Runnable { public void run() { //这里实现发送请求 } public static void ...

  10. hdu1166-敌兵布阵-分块

    把区间分成√n份降低复杂度. #include<bits/stdc++.h> #define inf 0x3f3f3f3f ; ; using namespace std; int t,n ...