The 12th Zhejiang Provincial Collegiate Programming Contest – D
最后更新于:2022-04-01 16:01:59
~~~
#include<cstdio>
#include<cstring>
using namespace std;
long long f[200005];
int vis[200005];
int main()
{
int t;
int n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
f[0]=0;
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
f[i]=x+f[i-1]+(i-1-vis[x])*x;
vis[x]=i;
}
long long ans=0;
for(int i=1;i<=n;i++)
ans+=f[i];
printf("%lld\n",ans);
}
return 0;
}
~~~