树状数组,把他们的技能值作为轴;

首先按照编号从小到大插入值,这样就可以得到,技能值比当前小的人数;

然后按照编号从大到小再插一遍;

代码:

 #include<cstdio>
#include<cstring>
#define maxn 20005
using namespace std; int a[maxn],c[];
int l[maxn],r[maxn];
int lowbit(int x){return x&-x;}
void add(int x,int d){while(x<=){c[x]+=d,x+=lowbit(x);}}
int sum(int x)
{
int ret=;
while(x>){ret+=c[x],x-=lowbit(x);}
return ret;
} int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
memset(c,,sizeof c);
memset(l,,sizeof l);
memset(r,,sizeof r);
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
add(a[i],);
l[i]=sum(a[i]-);
}
memset(c,,sizeof c);
for(int i=n;i>=;i--)
{
add(a[i],);
r[i]=sum(a[i]-);
}
long long ans=;
for(int i=;i<=n;i++)
ans+=l[i]*(n-i-r[i])+(i-l[i]-)*r[i];
printf("%lld\n",ans);
}
}

uva 1428 - Ping pong的更多相关文章

  1. UVA 1428 - Ping pong(树状数组)

    UVA 1428 - Ping pong 题目链接 题意:给定一些人,从左到右,每一个人有一个技能值,如今要举办比赛,必须满足位置从左往右3个人.而且技能值从小到大或从大到小,问有几种举办形式 思路: ...

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

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

  3. UVALive 4329 Ping pong

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

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

                                                                          Ping pong Time Limit: 1000MS   ...

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

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

  6. Ping pong

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

  7. POJ 3928 Ping pong

    题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...

  8. Frequent values && Ping pong

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

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

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

随机推荐

  1. linux 提高进程优先级nice+ 进程调度CFS

    http://www.cnblogs.com/wang_yb/archive/2012/09/04/2670564.htmlhttp://liwei.life/2016/04/07/linux%E7% ...

  2. TCP/IP 编程

    http://www.cnblogs.com/ggjucheng/archive/2012/08/18/2645324.html

  3. careercup-数组和字符串1.3

    1.3 给定两个字符串,请编写程序,确定其中一个字符串的字符重新排序后,能否变成另一个字符串. C++实现代码: #include<iostream> #include<map> ...

  4. view中的setTag和getTag方法的理解

    下面是一段自定义适配器中的getView方法,其中使用了view的一个setTag和getTag方法 View中的setTag(Onbect)表示给View添加一个格外的数据(相当于缓存),以后可以用 ...

  5. magic_quotes_sybase(魔术引号开关)

    magic_quotes_sybase,如果该选项在php.ini文件中是唯一开启的话,将只会转义%00为\0(即null字符).此选项会完全覆盖magic_quotes_gpc.如果同时开启这两个选 ...

  6. 处理json中影响解析的多余引号

    在xml中,敏感字符是尖括号,在json中,敏感字符是引号,上文中我们介绍了如何处理xml中的敏感字符,本文说说如何处理json中的敏感字符. 思路与上文相同,不再赘述.直接上代码: json–> ...

  7. switch vpn 配置

  8. Asp.net简单三层+Sqllite 增删改查

    新建项目à新建一个空白解决方案 在Model新建一个实体类 using System; using System.Collections.Generic; using System.Linq; usi ...

  9. 高效删除 ListItem

    The most efficient way to a lot of transaction in SharePoint is using of SPWeb.ProcessBatchData meth ...

  10. C#中有关字符串去重的解决方案

    今天在群里看到一个同学的面试题 题目中有一个这样的要求 //本地有个文档文件a.txt里面包含的内容分为一段字符串"abacbacde"请编写一个程序,获取文件得到对应的内容,并对 ...