标签:des style blog http java color
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2224 Accepted Submission(s): 701
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 #include <math.h> 5 #include <string.h> 6 #include <set> 7 #include <queue> 8 using namespace std; 9 #define ll long long 10 typedef struct abcd 11 { 12 ll sum,n; 13 } abcd; 14 abcd a[110000]; 15 ll lowbit(ll x) 16 { 17 return x&(-x); 18 } 19 ll update(ll x) 20 { 21 int y=x; 22 while(x<110000) 23 { 24 a[x].n++; 25 a[x].sum+=y; 26 x+=lowbit(x); 27 } 28 } 29 ll fun(ll x) 30 { 31 ll ans=0; 32 while(x>0) 33 { 34 ans+=a[x].n; 35 x-=lowbit(x); 36 } 37 return ans; 38 } 39 ll fun1(ll x) 40 { 41 ll ans=0; 42 while(x>0) 43 { 44 ans+=a[x].sum; 45 x-=lowbit(x); 46 } 47 return ans; 48 } 49 int main() 50 { 51 ll n,i,x,ans,z,sum; 52 while(~scanf("%I64d",&n)) 53 { 54 memset(a,0,sizeof(a)); 55 sum=ans=0; 56 for(i=0; i<n; i++) 57 { 58 scanf("%I64d",&x); 59 sum+=x; 60 z=fun(x); 61 update(x); 62 ans+=(i-z)*x+sum-fun1(x); 63 } 64 cout<<ans<<endl; 65 } 66 }
Cow Sorting hdu 2838,布布扣,bubuko.com
标签:des style blog http java color
原文地址:http://www.cnblogs.com/ERKE/p/3837772.html