http://acm.nyist.net/JudgeOnline/problem.php?pid=117&&树状数组求逆序数+离散化
来源:互联网 发布:开淘宝网店有赚钱的吗 编辑:程序博客网 时间:2024/06/04 19:47
这一题一开始是胸有成竹的,本想1A的,但是接二连三的wa了好几次。。。把我满满的自信心消磨殆尽了。。我一遍一遍的寻找错误,就是找不到。。最后实在没办法要了后台的数据。。运行一看。令我大跌眼眶。。。。竟然都对了,,但为什么WA呢?可能是这一题判题写错了?,最后在不抱希望的情况下我把%I64d改成了%lld,竟然AC了,苦逼的孩子。。oj竟然不支持%I64d.....
AC代码:
#include<iostream>#include<cstdio>#include<algorithm>#include<string.h>#define N 1000005using namespace std;int s[N];int kp[N];int a[N];int tot;typedef long long L;int lowbit(int x){return x&(-x);}void update(int x){while(x<N) { s[x]++; x+=lowbit(x); }}L Quary(int x){ L sum=0; while(x>0) { sum+=s[x]; x-=lowbit(x); } return sum;}int lisan(int x){ int l=1,r=tot; while(l<=r) { int mid=(l+r)>>1; if(a[mid]==x) return mid; else if(a[mid]<x) l=mid+1; else if(a[mid]>x) r=mid-1; }}int main(){ int T; //freopen("d:\\1.txt","r",stdin); //freopen("d:\\2.txt","w",stdout); scanf("%d",&T); while(T--) { memset(s,0,sizeof(s)); int n; scanf("%d",&n);tot=0;for(int i=1;i<=n;++i){scanf("%d",&kp[i]); a[i]=kp[i]; }sort(a+1,a+n+1);for(int i=1;i<=n;++i) if(i==1||a[i]!=a[i-1]) a[++tot]=a[i];L res=0; for(int i=1;i<=n;++i) { int num=lisan(kp[i]); update(num);res+=i-Quary(num); } printf("%lld\n",res); }return 0;}
- http://acm.nyist.net/JudgeOnline/problem.php?pid=117&&树状数组求逆序数+离散化
- http://acm.nyist.net/JudgeOnline/problem.php?pid=290
- http://acm.nyist.net/JudgeOnline/problem.php?pid=434
- http://acm.nyist.net/JudgeOnline/problem.php?pid=13
- http://acm.nyist.net/JudgeOnline/problem.php?pid=239
- http://acm.nyist.net/JudgeOnline/problem.php?pid=129
- http://acm.nyist.net/JudgeOnline/problem.php?pid=431
- http://acm.nyist.net/JudgeOnline/problem.php?pid=301
- http://acm.nyist.net/JudgeOnline/problem.php?pid=451
- http://acm.nyist.net/JudgeOnline/problem.php?pid=459
- http://acm.nyist.net/JudgeOnline/problem.php?pid=20
- http://acm.nyist.net/JudgeOnline/problem.php?pid=267
- http://acm.nyist.net/JudgeOnline/problem.php?pid=305
- http://acm.nyist.net/JudgeOnline/problem.php?pid=309
- http://acm.nyist.net/JudgeOnline/problem.php?pid=325
- http://acm.nyist.net/JudgeOnline/problem.php?pid=420
- http://acm.nyist.net/JudgeOnline/problem.php?pid=488
- http://acm.nyist.net/JudgeOnline/problem.php?pid=150
- java设计模式之享元模式
- 【每日面试题】给定一个字符串,求出其最长的重复子串
- Qt中使用Cairo
- Linux上的ftp配置,及错误500 OOPS: could not bind listening IPv4 socket解决
- c++操作word接口
- http://acm.nyist.net/JudgeOnline/problem.php?pid=117&&树状数组求逆序数+离散化
- Poem: I Like For You To Be Still
- Socket编程
- Nginx 的 server_names_hash_bucket_size 问题
- 用 jQuery写的可编辑的表格
- Visual C++操纵MS Word
- 九选三不及格,心情沉痛ing
- Linux设备驱动开发学习步骤
- * java版HashMap,大数据量时效率很低,建议1000条数据以下使用