树状数组求逆序对
来源:互联网 发布:温度测试仪软件 编辑:程序博客网 时间:2024/05/16 11:28
题目>>http://codevs.cn/problem/1688/
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int MAXN = 1e6 + 5;long long tree[MAXN],n,a,ans = 0;void add(long long x){ while(x <= 1e5) { tree[x] ++; x += (x & (-x)); }}long long sum(long long x){ long long ans = 0; while(x) { ans += tree[x]; x -= (x & (-x)); } return ans;}int main(){ scanf("%lld",&n); for(long long i = 1;i <= n;i ++) { scanf("%lld",&a); add(a);//以树状数组为桶并记录个数。 ans += i - sum(a);//容斥,比这个数大的数 = 总的数的个数 - 比他小的。 } printf("%lld",ans);}
阅读全文
0 0
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- 树状数组求逆序对
- poj 3067(树状数组求逆序对)
- 树状数组+离散化求逆序对
- 求逆序对 (树状数组版)
- hdu2838Cow Sorting树状数组求逆序对
- 发送自定义事件
- max-points-on -a-line
- HDU3072 Intelligence System【最小树形图】
- 《数据库SQL实战》统计出当前各个title类型对应的员工当前薪水对应的平均工资。
- Java注解(二):注解处理器
- 树状数组求逆序对
- 堆棋子
- Mysql数据表管理
- 模板模式的应用
- RecastNavigation-NavMesh生成原理
- Android WebView 调试方法
- linux 内核驱动中对文件的读写
- 使用Python操作MongoDB
- HDU-1730-Northcott Game【nimm 博弈】