标签:des style blog http io ar os sp for
#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; long long ans[100010]; int kid[100010]; int bit[1000010]; int n; void add(int x) { int i; for(i=x;i<=n;i+=i&-i) bit[i]++; } int psum(int x) { int i,sum; sum=0; for(i=x;i>0;i-=i&-i) sum+=bit[i]; return sum; } int main() { int m,i; long long x; cin>>m; for(i=0;i<m;i++) { cin>>kid[i]; kid[i]++; n=max(n,kid[i]); } for(i=0;i<m;i++) { ans[i]=psum(n)-psum(kid[i]); add(kid[i]); } memset(bit,0,sizeof(bit)); for(i=m-1;i>-1;i--) { ans[i]+=psum(kid[i]-1); add(kid[i]); } x=0; for(i=0;i<m;i++) x+=(1+ans[i])*ans[i]/2; cout<<x; return 0; }
标签:des style blog http io ar os sp for
原文地址:http://blog.csdn.net/stl112514/article/details/41909125