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

因此可以利用树状数组,从左到右往树上插点,每个点询问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. .Net HttpWebRequest 爬虫核心爬取

    1 爬虫,爬虫攻防 2 下载html 3 xpath解析html,获取数据和深度抓取(和正则匹配) 4 多线程抓取 熟悉http协议 提供两个方法Post和Get public static stri ...

  2. Excel .net读取

    public void LoadData(string StyleSheet) { string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Dat ...

  3. Cinder服务使用

    Cinder环境 Cinder配置 重新创建卷组cinder-volumes [root@openstack centos]# vgremove cinder-volumes Configuratio ...

  4. GoWeb开发_Iris框架讲解(一)

    Golang介绍 Go语言是谷歌推出的一种全新的编程语言,可以在不损失应用程序性能的情况下降低代码的复杂性.谷歌首席软件工程师罗布派克(Rob Pike)说:我们之所以开发Go,是因为过去10多年间软 ...

  5. solidity 学习笔记(7)内联汇编

    为什么要有内联汇编? //普通循环和内敛汇编循环比较 pragma solidity ^0.4.25; contract Assembly{ function nativeLoop() public ...

  6. css3中-moz、-ms、-webkit、-o

    -moz代表firefox浏览器私有属性-ms代表IE浏览器私有属性-webkit代表chrome.safari私有属性-o代表opera私有属性

  7. IDEA导入HttpServlet包

    转载此篇博客,言简意赅.https://blog.csdn.net/liu_yanzhao/article/details/78838670

  8. swift 广告轮播图

    import UIKit import Kingfisher class BannerView: UIView,UIScrollViewDelegate{ enum ImageType{ case I ...

  9. ES6新特性使用小结(四)

    十一.Proxy .Reflect ①.Proxy 的概念和常用方法 { let obj = { //1.定义原始数据对象 对用户不可见 time: '2017-09-20', name: 'net' ...

  10. 070 Climbing Stairs

    你正在爬楼梯.需要 n 步你才能到达顶部.每次你可以爬 1 或 2 个台阶.你有多少种不同的方式可以爬到楼顶呢?注意:给定 n 将是一个正整数.示例 1:输入: 2输出: 2说明: 有两种方法可以爬到 ...