http://poj.org/problem?id=2299 树状数组 《复习》
来源:互联网 发布:制作宣传栏软件 编辑:程序博客网 时间:2024/05/16 15:04
//求解逆序数对:(后面的数比当前的数小的个数)//例:9 1 0 5 4//9的逆序数:91 90 95 94 共有4个//1的逆序数: 10 共有1个//0的逆序数: 为0个//5的逆序数:54为1个//4的逆序数:0个//所以9 1 0 5 4的逆序数共有6个#include<iostream>#include<algorithm>#include<cstdio>#include<string.h>using namespace std;struct node{ int x; int pox;}Node[501000];int num[501000];int cmp(node a,node b){ return a.x>b.x;}int lowbit(int x){ return -x&x;}void upData(int n,int T){ while(n<T) { num[n]+=1; n+=lowbit(n); }}int getSum(int n){ int ans=0; while(n>0) { ans+=num[n]; n-=lowbit(n); } return ans;}int main(){ int T; __int64 ans; while(scanf("%d",&T),T) { ans=0; memset(Node,0,sizeof(Node)); memset(num,0,sizeof(num)); for(int i=0;i<T;i++) { scanf("%d",&Node[i].x); Node[i].pox=i+1; } sort(Node,Node+T,cmp); for(int i=0;i<T;i++) { ans+=getSum(Node[i].pox-1); upData(Node[i].pox,T); } printf("%I64d\n",ans); } return 0;}
- http://poj.org/problem?id=2299 树状数组 《复习》
- http://poj.org/problem?id=1195二维树状数组
- http://poj.org/problem?id=2481 树状数组+优先队列
- http://poj.org/problem?id=2965
- http://poj.org/problem?id=2075
- http://poj.org/problem?id=1125
- http://poj.org/problem?id=2983
- http://poj.org/problem?id=2406
- http://poj.org/problem?id=1961
- http://poj.org/problem?id=1486
- http://poj.org/problem?id=1062
- http://poj.org/problem?id=2983
- http://poj.org/problem?id=3159
- http://poj.org/problem?id=1201
- http://poj.org/problem?id=3259
- http://poj.org/problem?id=3233
- http://poj.org/problem?id=1273
- http://poj.org/problem?id=3281
- android 用Luncher启动应用的方式
- oracle监听注册
- linux timestamp
- Python_使用python解释器执行monkey runner脚本
- 线程的最佳实践一:不覆写Thread.start()方法
- http://poj.org/problem?id=2299 树状数组 《复习》
- 解读Cardinality Estimation算法(第一部分:基本概念)
- FFMpeg的解码流程
- 自定义的三个Oracle日期函数 dayadd datediff datepart
- Cocos2d_code fragment(2)
- Servlet映射规则和Servlet URL映射匹配原则
- 复用器
- 索引性能好不好让二元高度来说话
- HDU2005 (第几天? 闰年)