树状数组逆序对
来源:互联网 发布:Sql中not in的效率 编辑:程序博客网 时间:2024/04/30 03:32
#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#define LL long longusing namespace std;LL a[500000],c[500000]={0}; LL n,ans=0,rr=0;struct kl{ LL x,pos;}re[500000];bool comp(kl q,kl y) {return (q.x<y.x);}LL lowbit(LL x){ return x&-x;}LL sum(LL x){ LL as=0; while (x>0) { as+=c[x]; x-=lowbit(x); } return as;}void add(LL x){ while (x<=n) { c[x]++; x+=lowbit(x); }}int main(){ scanf ("%lld",&n); for (int o=1;o<=n;++o) { scanf ("%lld",&re[o].x); re[o].pos=o; } sort(re+1,re+n+1,comp); for (int i=1;i<=n;++i) { if (re[i].x!=re[i-1].x) rr++; a[re[i].pos]=rr; } for (int i=1;i<=n;++i) { add(a[i]); ans+=i-sum(a[i]); //cout<<sum(a[i])<<endl; } cout<<ans; return 0; }
0 0
- 树状数组逆序对
- poj1007 树状数组逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 逆序对-树状数组-1
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组 求解 逆序数对
- 利用ansible-playbook从测试环境获取tomcat中java项目新版本发布到生产环境
- leveldb实例
- python 中的None
- Codeforces Round #257 (Div. 1) A - Jzzhu and Chocolate 2017/1/11
- Android6.0 如何添加更改系统设置权限
- 树状数组逆序对
- Maven精华文章收录
- Three.JS学习 5:了解相机
- linux-shell命令之rm(remove)【删除文件或目录】
- GMssl -- 1
- 【Unity&NGUI】背包系统显示隐藏问题
- c——复合类型——字符串
- 朴素贝叶斯
- 关于HTTP协议,一篇就够了