标签:它的 new include blog lowbit input order cat ber
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1143 Accepted Submission(s): 387
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define LL long long 4 int sumv[100000+15]; 5 int c[20005],d[20005],a[20005]; 6 int lowbit(int x){return x&-x;} 7 int sum(int x) 8 { 9 int ret=0; 10 while(x){ 11 ret+=sumv[x]; 12 x-=lowbit(x); 13 } 14 return ret; 15 } 16 void add(int x,int d) 17 { 18 while(x<=100000){ 19 sumv[x]+=d; 20 x+=lowbit(x); 21 } 22 } 23 int main() 24 { 25 int N,t,m,i,j,k; 26 scanf("%d",&t); 27 while(t--){memset(sumv,0,sizeof(sumv)); 28 LL ans=0; 29 scanf("%d",&N); 30 for(i=1;i<=N;++i){ 31 scanf("%d",&a[i]); 32 add(a[i],1); 33 c[i]=sum(a[i]-1); 34 }memset(sumv,0,sizeof(sumv)); 35 for(i=N;i>=1;--i){ 36 add(a[i],1); 37 d[i]=sum(a[i]-1); 38 } 39 for(i=1;i<=N;++i){ 40 ans+=(LL)c[i]*(N-i-d[i])+d[i]*(i-1-c[i]); 41 } 42 printf("%lld\n",ans); 43 } 44 return 0; 45 }
标签:它的 new include blog lowbit input order cat ber
原文地址:http://www.cnblogs.com/zzqc/p/7267065.html