树状数组。考虑ai(从0开始,则i左边共i个,右边n-i-1个),左边有x个比他大的,i-x个比他小的,右边有y个比他大的,n-i-1-y个比他大的。交叉乘一下就得到了以ai为裁判的比赛总数。把所有人都枚举一遍,加在一起就是答案,会超int。

如何才能知道ai左边有多少比他小的呢?假如aj<ai且j<i,用另一个数组b来标记这个数有没有出现过,那么b[aj] = 1;这样,比ai小的数的个数,就是b的前缀和。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<cmath>
///LOOP
#define REP(i, n) for(int i = 0; i < n; i++)
#define FF(i, a, b) for(int i = a; i < b; i++)
#define FFF(i, a, b) for(int i = a; i <= b; i++)
#define FD(i, a, b) for(int i = a - 1; i >= b; i--)
#define FDD(i, a, b) for(int i = a; i >= b; i--)
///INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RFI(n) scanf("%lf", &n)
#define RFII(n, m) scanf("%lf%lf", &n, &m)
#define RFIII(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define RFIV(n, m, k, p) scanf("%lf%lf%lf%lf", &n, &m, &k, &p)
#define RS(s) scanf("%s", s)
///OUTPUT
#define PN printf("\n")
#define PI(n) printf("%d\n", n)
#define PIS(n) printf("%d ", n)
#define PS(s) printf("%s\n", s)
#define PSS(s) printf("%s ", n)
///OTHER
#define PB(x) push_back(x)
#define CLR(a, b) memset(a, b, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(b))
#define display(A, n, m) {REP(i, n){REP(j, m)PIS(A[i][j]);PN;}}using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = 100000000;
const int INFI = 1e9 * 2;
const LL LINFI = 1e17;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int N = 111111;
const int M = 22;
const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};int a[N], b[N], c[N], n;void update(int x)
{while(x <= N){b[x]++;x += x & (-x);}
}int sum(int x)
{LL s = 0;while(x){s += b[x];x -= x & (-x);}return s;
}int main()
{//freopen("input.txt", "r", stdin);//freopen("output.txt", "w", stdout);int t, k;LL ans;RI(t);while(t--){RI(n);CLR(b, 0);REP(i, n){RI(a[i]);c[i] = sum(a[i]);update(a[i]);}CLR(b, 0);ans = 0;FD(i, n, 0){k = sum(a[i]);ans += LL(c[i]) * LL(n - i - 1 - k) + LL(i - c[i]) * LL(k);update(a[i]);}printf("%lld\n", ans);}return 0;
}

转载于:https://www.cnblogs.com/suncoolcat/p/3290212.html

UVALive 4329 Ping pong相关推荐

  1. [UVALive - 4329] Ping pong 树状数组入门

    题目链接:Ping pong 题意 给你n个数,你从中取3个数,要求中间的数字大小在两边数字之间.问你总共有多少种取法. 题解 这个题首先需要分析转化. 假设第i个人作为中间数 a1-ai−1有ci个 ...

  2. Ping pong【树状数组】

    Ping pong UVALive - 4329 题目传送门 题目大意:一条大街上住着n个乒乓球爱好者,经常组织比赛切磋技术.每个人都有一个不同的技能值ai.每场比赛需要三个人:两名选手,一名裁判.他 ...

  3. 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 ...

  4. ping/pong模式_PING的完整形式是什么?

    ping/pong模式 PING:数据包InterNet Groper (PING: Packet InterNet Groper) In the sector of networking of co ...

  5. Unity3D 4.x怎样实现动画的Ping Pong效果

    近期在看Unity官方的Stealth项目教学视频.视频使用的是Unity旧的版本号,而我如今正在使用的是Unity 4.5,动画系统的操作全然不同了.依照视频的方式根本无法设置动画的Ping Pin ...

  6. HDOJ 2492 Ping pong 线段树+离散化

    //2492 Ping pong 线段树+离散化 /* 题意: 有一陀人从左到右排成一排,每个人有一个唯一的技能值,每个人都找其他人比赛, 比赛前要再找一个人做裁判,裁判的技能值不能比这两个人都高,也 ...

  7. go-gorilla的ping pong

    业务需求,ping每隔60秒执行一次,ping两次后,没有得到pong的消息,自动切断client. pongTime=180 * time.Second pingTime=60 * time.Sec ...

  8. ping pong buffer

    Ping pong buffer is a buffer used in a transmission that contains two separate buffers, while one bu ...

  9. Ping Pong Buffer 双缓冲 C++代码学习

    1.Ping Pong Buffer 原理分析 基本原理如上图所示,当设备有数据来时,先放入缓冲区1 然后将缓冲区1的数据放入缓冲区2,这时缓冲区1可接收下次数据.工作区可从缓冲区2拿数据 2.C++ ...

最新文章

  1. linux shell 脚本攻略学习10--生成任意大小的文件和文本文件的交集与差集详解
  2. day18 17.c3p0连接池使用
  3. H5存储------localStorage和sessionStorage
  4. qt4.8添加mysql驱动_Windows下编译Qt4.8 MySQL数据库驱动
  5. 压箱底总结:流系统端到端一致性对比
  6. 发现Java程序中的Bug
  7. Java知识积累——同时输出到控制台和指定文件,或直接输出到指定文件
  8. 零基础学python实战-Python3零基础入门到爬虫实战
  9. HTML5网页语音识别功能演示
  10. MOE 分子动力学模拟操作
  11. 主流数据持久层框架特性与实践
  12. texlive的安装
  13. 关于rollup 和cude 举例浅分析
  14. 电脑服务器不小心删除文件怎么办,电脑不小心删除的文件可以恢复吗?
  15. 华为前端社招OD面试(已拿offer)
  16. OpenGL——场景设计
  17. 贝叶斯神经网络 BNN
  18. antd vue表单验证_解决antd 表单设置默认值initialValue后验证失效的问题
  19. 12306 抢票,极限并发带来的思考
  20. 打开PS出现Unable to continue because of a hardware quo

热门文章

  1. 系数矩阵为方阵的线性方程组解的情况
  2. leetcode - 813. 最大平均值和的分组
  3. JS-深入理解继承(非class方式与class继承)
  4. Pytorch 之Tensor 初探
  5. matlab STFT从时频图找异常噪声的频率
  6. MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainC
  7. Spring IOC注解开发
  8. toj 4613 Number of Battlefields
  9. 最大子序列和的四种求解算法及其时间比较
  10. c语言大学期末考试题及答案,大学C语言期末考试题4及答案