SGU 180 Inversions (树状数组+离散化)
来源:互联网 发布:oauth2.0 java 服务端 编辑:程序博客网 时间:2024/05/16 19:37
Inversions
Time Limit: 250MS Memory Limit: 4096KB 64bit IO Format: %I64d & %I64u
Submit
Status
Description
180. Inversions
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard
output: standard
There are N integers (1<=N<=65537) A1, A2,.. AN (0<=Ai<=10^9). You need to find amount of such pairs (i, j) that 1<=i< j<=N and A[i]>A[j].
Input
The first line of the input contains the number N. The second line contains N numbers A1…AN.
Output
Write amount of such pairs.
Sample test(s)
Input
5
2 3 1 5 4
Output
3
Author: Stanislav Angelyuk
Resource: Saratov ST team Spring Contest #1
Date: 18.05.2003
水树状数组
#include <cstring>#include <cstdio>#include <iostream>#include <string.h>#include <algorithm>#include <vector>using namespace std;int n;int num[70000];int tree[70000*4];vector <int> list;int cnt=0;int lowbit(int x){ return x&(-x);}void update(int x){ for(int i=x;i<=cnt;i+=lowbit(i)) tree[i]++;}int sum(int x){ int ans=0; for(int i=x;i>0;i-=lowbit(i)) ans+=tree[i]; return ans;}int main(){ while(~scanf("%d",&n)) { list.clear(); memset(tree,0,sizeof(tree)); for(int i=1;i<=n;i++) { scanf("%d",&num[i]); list.push_back(num[i]); } sort(list.begin(),list.end()); list.erase(unique(list.begin(),list.end()),list.end()); cnt=list.size(); long long ans=0; for(int i=n;i>=1;i--) { int pos=lower_bound(list.begin(),list.end(),num[i])-list.begin()+1; update(pos); ans+=sum(pos-1); } printf("%lld\n",ans); }}
0 0
- SGU 180 Inversions (树状数组+离散化)
- SGU 180-Inversions(树状数组离散化求逆序对数)
- SGU 180. Inversions 离散 + 树状数组
- sgu 180. Inversions (树状数组+离散化,第一道需要改模板的题目,好题)
- SUG 180 Inversions(树状数组+离散化)
- sgu180 Inversions(树状数组+离散化)
- SGU 180 Inversions(树状数组求逆序对)
- SGU 180 Inversions <一维树状数组区间查询>
- Codeforces 540E Infinite Inversions 离散化+树状数组
- codeforces 540 E. Infinite Inversions (离散化 + 树状数组)
- CodeForces-540E Infinite Inversions(树状数组+离散化+加点)
- sgu 180 Inversions
- SGU 180 Inversions
- SGU 180 Inversions
- SGU 180 Inversions
- SGU180:Inversions(树状数组)
- 树状数组--离散化
- sgu 180(树状数组)
- HDU-1251 统计难题
- spring mvc注解代码实例教程
- easyui datagrid 分页详解
- POJ 2546 Circular Area(计算几何 两圆相交面积)
- python Import 学习笔记
- SGU 180 Inversions (树状数组+离散化)
- [leetcode] 144. Binary Tree Preorder Traversal
- Android studio真机模拟调试
- java虚拟机-HotSpot的算法实现
- checkbox 全选
- R语言环境在Ubuntu下的安装
- viewpager切换动画
- Android学习历程--Launcher拖拽流程
- 在普通java类里获取Spring管理的bean