UVA1428
来源:互联网 发布:汉服复原小组淘宝 编辑:程序博客网 时间:2024/05/18 20:13
n个人,从左到右排列,每个人都有一个不一样技能值 arr[i], 每场比赛3个人: 两名选手, 一名裁判。 裁判必须在两名选手中间, 并且技能值也在两名选手之间, 问一共能组织多少种比赛。
树状数组的基本应用。
#include<cstdio>#include<cstring>#include<algorithm>#define LL long long#define maxn 100010using namespace std;LL left[maxn],c[maxn],arr[maxn];int lowbit(int x){ return x&(-x);}LL sum(int i){ LL sum=0; while(i>0) { sum+=c[i]; i-=lowbit(i); } return sum;}void add(int i,LL x){ while(i<maxn) { c[i]+=x; i+=lowbit(i); }}int main(){ int cas,n; scanf("%d",&cas); while(cas--) { scanf("%d",&n); memset(c,0,sizeof(c)); for(int i=0; i<n; i++) { scanf("%d",&arr[i]); left[i]=0; } for(int i=0; i<n; i++) { left[i]=sum(arr[i]); add(arr[i],1); } LL ans = 0; memset(c,0,sizeof(c)); for(int i=n-1; i>=0; i--) { LL d=sum(arr[i]); add(arr[i],1); ans+=(left[i]*(n-i-1-d)+d*(LL)((LL)i-left[i])); } printf("%lld\n",ans); } return 0;}
0 0
- UVA1428
- 树状数组uva1428
- UVA1428树状数组
- poj1990&&uva1428 树状数组
- UVa1428 - Ping pong
- uva1428 Ping pong
- 【UVA1428】Ping pong
- UVA1428 Ping pong(树状数组)
- UVA1428 - Ping pong(树状数组)
- 例题3.7 乒乓比赛 UVa1428
- UVA1428 Ping pong(树状数组)
- UVA1428 Ping pong(树状数组)
- POJ 3928 & hdu 2492 & Uva1428 PingPong 【树状数组】
- (win7 64位系统)VMware Workstation 11安装Mac OS X 10.10虚拟苹果系统
- 详解mysql int类型的长度值问题
- linux中select()函数分析
- 看好你的门-客户端传数据(1)-不安全的隐藏表单字段
- PLSQL查询结果中文乱码
- UVA1428
- TeeChart8.0注册
- 连载:告诉你如何设计一个日访问量千万级别的系统,谈oracle的高级设计和开发(1)
- Android程序员必备精品资源
- PAT1068 Find More Coins (背包问题)
- 《穹顶之下》的思考:柴静改变不了什么!
- Android性能专项测试之battery-historian试用
- “default”标签跳过“ ”的初始化操作问题解决
- 【图像处理】透视变换 Perspective Transformation