#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
#define PF(x) (scanf("%d",&x))
#define PT(x,y) (scanf("%d%d",&x,&y))
#define PR(x) (printf("%d\n",(x)))
#define PRT(x,y)(printf("%d %d\n",x,y))
#define M 100005
typedef __int64 LL;
LL arr[M];
LL n,m;
LL ar[M];
int maxx(int x,int y)
{
return x>y?x:y;
}
int minx(int x,int y)
{
return x>y?y:x;
}
LL low(LL x)
{
return x&(-x);
}
void add(LL *ac,LL x,LL c)
{
for(x;x<M;x+=low(x))
ac[x]+=c;
}
LL sums(LL *ac,LL x)
{
LL sumt = 0;
for(;x;x-=low(x))
sumt += ac[x];
return sumt;
}
void init()
{
while(scanf("%I64d",&n)!=EOF)
{
memset(arr,0,sizeof(arr));
memset(ar,0,sizeof(ar));
LL ans = 0;
for(int i=0;i<n;i++)
{
LL x;
scanf("%I64d",&x);
ans += sums(arr,n)-sums(arr,x)+(sums(ar,n)-sums(ar,x))*x;
add(arr,x,x);
add(ar,x,1);
}
printf("%I64d\n",ans);
}
return ;
}
int main()
{
init();
return 0;
}
hdu 2838
最新推荐文章于 2020-08-11 08:53:56 发布