hiho~ 分类: hiho templates 2015-04-01 17:37 32人阅读 评论(0) 收藏
2015-04-01 17:37
375 查看
http://hihocoder.com/contest/hiho39/problem/1#
逆序对裸题,水题
逆序对裸题,水题
#include<map> #include<string> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<cmath> #include<iostream> #include<algorithm> #define LowBit(x) ((x)&(-(x))) const int MAXN = 100005; int n,nn; int a[MAXN] = {0},b[MAXN] ={0}; int sum[MAXN] = {0}; long long ans = 0; void insert(int x) { while(x <= n) { sum[x] ++; x += LowBit(x); } } int count(int x) { int ret = 0; while(x > 0) { ret += sum[x]; x-=LowBit(x); } return ret; } int main() { #ifndef ONLINE_JUDGE freopen("hiho.in","r",stdin); freopen("hiho.out","w",stdout); #endif scanf("%d",&n); for(int i = 1; i <= n ;i++) {scanf("%d",&a[i]); b[i] = a[i];} std::sort(b + 1, b + n + 1); nn = std::unique(b + 1,b + n + 1)- (b + 1); for(int i = 1; i <= n; i++) { static int bi; bi = std::lower_bound(b + 1, b + nn + 1,a[i]) - b; ans += count(n) - count(bi); insert(bi); } std::cout << ans; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
相关文章推荐
- leetCode(32):Power of Two 分类: leetCode 2015-07-07 10:40 205人阅读 评论(0) 收藏
- iOS UIButton各类属性设置大全 分类: ios开发 2015-04-01 16:39 185人阅读 评论(0) 收藏
- poj 3468 分类: poj templates 2015-04-01 20:20 34人阅读 评论(0) 收藏
- sgu 153 分类: sgu templates 2015-04-26 16:35 32人阅读 评论(0) 收藏
- iOS开发~CocoaPods使用详细说明 分类: ios相关 2015-04-01 16:45 68人阅读 评论(0) 收藏
- 2015-03 月份学习总结 分类: 学习总结 2015-04-01 20:25 88人阅读 评论(0) 收藏
- 2015-03 月份学习总结 分类: 学习总结 2015-04-01 20:25 87人阅读 评论(0) 收藏
- 转自知乎,亲民好酒推荐 分类: fool_tree的笔记本 2014-11-08 17:37 652人阅读 评论(0) 收藏
- NYOJ-32 组合数 AC 分类: NYOJ 2013-12-30 07:42 189人阅读 评论(0) 收藏
- 定时器NSTimer 分类: ios开发 2015-04-01 20:34 177人阅读 评论(0) 收藏
- android开发之broadcast学习笔记 分类: android 学习笔记 2015-07-19 16:33 32人阅读 评论(0) 收藏
- poj 2516 分类: poj templates 2015-04-04 13:38 32人阅读 评论(0) 收藏
- FFMPEG:H264解码-SDL显示(RGB32、RGB24、YUV420P、YUV422) 分类: DirectX ffmpeg-SDL-VLC-Live555 VC++ 2014-11-25 17:45 726人阅读 评论(0) 收藏
- sgu 179 分类: sgu 2015-03-11 21:25 32人阅读 评论(0) 收藏
- Python异常处理 分类: python Raspberry Pi 服务器搭建 2015-04-01 13:22 172人阅读 评论(0) 收藏
- poj 2018 分类: poj 2015-04-22 13:48 32人阅读 评论(0) 收藏
- NYOJ-32 组合数 AC 分类: NYOJ 2014-01-02 22:21 112人阅读 评论(0) 收藏
- 2的32次方 分类: C#小技巧 2014-08-05 18:18 406人阅读 评论(0) 收藏
- bzoj 3560 分类: bzoj 2015-04-01 21:43 40人阅读 评论(0) 收藏
- 图像处理------直方图均衡化 分类: 视频图像处理 2015-07-24 14:54 32人阅读 评论(0) 收藏