63 lines
1.2 KiB
C++
63 lines
1.2 KiB
C++
#include<iostream>
|
|
#include<iostream>
|
|
#include<cstring>
|
|
#include<algorithm>
|
|
#include<cassert>
|
|
#include<string>
|
|
#include<cstdio>
|
|
#include<queue>
|
|
#include<map>
|
|
using namespace std;
|
|
typedef long long LL;
|
|
const int maxn=2e5+10,maxv=3e5+10;
|
|
class BST
|
|
{
|
|
LL mem[maxv];
|
|
public:
|
|
inline void add(int p,LL v)
|
|
{
|
|
for(;p<maxv;p+=p&(-p))
|
|
mem[p]+=v;
|
|
}
|
|
inline LL query(int p)
|
|
{
|
|
LL res=0;
|
|
for(;p>0;p-=p&(-p))
|
|
res+=mem[p];
|
|
return res;
|
|
}
|
|
}num_cnt,value_tot,pre_influence;
|
|
int n,a[maxn];
|
|
LL res=0;
|
|
int main()
|
|
{
|
|
#ifdef local
|
|
freopen("pro.in", "r", stdin);
|
|
// freopen("pro.out","w",stdout);
|
|
#endif
|
|
scanf("%d",&n);
|
|
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
|
|
for(int i=1;i<=n;i++)
|
|
{
|
|
LL delta=0;
|
|
// printf("i=%d\n",i);
|
|
delta+=LL(a[i])*num_cnt.query(maxv-1);
|
|
delta+=value_tot.query(maxv-1);
|
|
// printf("delta=%lld\n",delta);
|
|
for(int v=1,L=a[i];L<maxv;v++,L+=a[i])
|
|
{
|
|
int R=min(maxv-1,L+a[i]-1);
|
|
delta-=LL(a[i])*v*(num_cnt.query(R)-num_cnt.query(L-1));
|
|
}
|
|
delta-=pre_influence.query(a[i]);
|
|
res+=delta;
|
|
printf("%lld ",res);
|
|
num_cnt.add(a[i],1);
|
|
value_tot.add(a[i],a[i]);
|
|
for(int L=a[i];L<maxv;L+=a[i])
|
|
pre_influence.add(L,a[i]);
|
|
// puts("\n_______\n");
|
|
}
|
|
puts("");
|
|
return 0;
|
|
} |