hdu 4000 Fruit Ninja(树状数组)
2015-07-27 20:13
447 查看
[code]#include<stdio.h> #include<string.h> const int N=100000+5; const int m=100000007; int n,c ; int lowbit(int x) { return x&(-x); } void add(int x) { while(x<=n) { c[x]+=1; x+=lowbit(x); } } int sum(int x) { int ret=0; while(x>0) { ret+=c[x]; x-=lowbit(x); } return ret; } int main() { int cas=0,_,p; __int64 ans,t1,t2; scanf("%d",&_); while(_--) { scanf("%d",&n); memset(c,0,sizeof(c)); ans=0; for(int i=1;i<=n;i++) { scanf("%d",&p); add(p); t1=sum(p-1); t2=n-p-(i-t1-1); ans-=t2*t1; if(t2>=2) ans+=t2*(t2-1)/2; //ans%=m; } printf("Case #%d: %I64d\n",++cas,ans%m); } return 0; }
相关文章推荐
- UICollectionViewFlowLayout and UICollectionView
- hdu 4000 Fruit Ninja(树状数组)
- iOS UI篇 学习笔记 UIButton,UIImageView
- Gym 100703L Many questions 水题
- Gym 100703L Many questions 水题
- IOS--UI--LessonXib 可视化编程
- legacy boot与uefi boot
- hdu 2506 Buildings
- USACO——Sorting a Three-Valued Sequence
- [LeetCode] Unique Paths
- UI第一课,view视图,label 和一些常用方法
- UIResponder
- PHP中include和require的区别详解
- codeforces Gym 100500H H. ICPC Quest 水题
- IOS--UI 电影列表纯代码
- EasyUI TextBox的keypress
- iOS UI篇 学习笔记 UILabel
- PAT (Advanced Level) 1056. Mice and Rice (25) 模拟比赛,用queue辅助
- 初学iOS UI 用于交流与学习
- UESTC 94 Bracket Sequence(线段树的区间更新)