标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4110 Accepted Submission(s): 2920
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int MAXN=1100; int c[MAXN]; inline int Lowbit(int x) { return x&(-x); } void update(int i,int val) { for(i; i>0; i-=Lowbit(i)) c[i]+=val; } int sum(int i) { int temp=0; for(i; i<=MAXN; i+=Lowbit(i)) temp+=c[i]; return temp; } int main() { int i,n; int a; while(~scanf("%d",&n)) { int ans=0; memset(c,0,sizeof(c)); for(i=1; i<=n; i++) { scanf("%d",&a); ans+=sum(a); update(a,1); } cout<<ans<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/GeekZRF/p/5932147.html