hdu 2492
来源:互联网 发布:电信4g是什么网络模式 编辑:程序博客网 时间:2024/06/05 07:51
树状数组
#include <iostream>#include <string.h>#include <stdio.h>using namespace std;const int maxn1=100000;const int maxn2=20010;int c[maxn1+10],v[maxn2],l[maxn2],r[maxn2];int n;int lowbit(int x){return x&(-x);}void add(int x){while(x<=maxn1)//要细心{c[x]+=1;x+=lowbit(x);}}int sum(int x){int tot=0;while(x>0){tot+=c[x];x-=lowbit(x);}return tot;}int main(){int t;cin>>t;while(t--){scanf("%d",&n);int i,a;for(i=1;i<=n;i++) scanf("%d",&v[i]);memset(c,0,sizeof(c));for(i=1;i<=n;i++){add(v[i]);l[i]=sum(v[i]-1);}memset(c,0,sizeof(c));for(i=n;i>0;i--){add(v[i]);r[i]=sum(v[i]-1);}long long tot=0;for(i=1;i<=n;i++){tot+=l[i]*(n-i-r[i])+(i-1-l[i])*r[i];}printf("%I64d\n",tot);}return 0;}
- HDU 2492
- HDU 2492
- hdu 2492
- HDU 2492
- hdu 2492
- hdu 2492【树状数组】
- HDU 2492 Ping pong
- hdu 2492 Ping pong
- HDU 2492 Ping pong
- hdu 2492树状数组
- hdu 2492 Ping pong
- HDU 2492 Ping pong
- HDU 2492 Ping pong
- HDU 2492 PingPong
- HDU 2492 Ping pong
- HDU 2492 Ping pong
- hdu 2492后缀数组
- hdu 2492 Ping pong
- Your First Step to the Silverlight Voice/Video Chatting Client/Server
- 三年规划(2012-2014年)
- 关于servlet和jsp路径表达方式的不同
- set intersection问题求解(python版)
- android in practice_Preparing for configuration changes(MyMovies project)
- hdu 2492
- 基于jQuery的一个简单聊天室
- soj 1162. Sudoku[Special judge] 1317. Sudoku
- 解决lein在Administrator目录的方法
- without base relocation /fixed:no
- Keil中预定义的字符串
- 黑马程序员-关于java中变量的总结
- 运动估计与运动补偿
- GPS协议