ZOJ 3872 Beauty of Array
思路:看懂题目之后就随便做了...
#include<bits/stdc++.h> using namespace std; #define LL long long const int maxn = 100005; LL dp[maxn]; int hash[maxn]; int main() { int T; scanf("%d",&T); while (T--) { int n; memset(hash,0,sizeof(hash)); scanf("%d",&n); dp[0]=0; for(int i=1;i<=n;i++) { int temp; scanf("%d",&temp); dp[i]=dp[i-1]+temp+(i-1-hash[temp])*temp; hash[temp]=i; } LL ans=0; for(int i=1;i<=n;i++) ans+=dp[i]; printf("%lld\n",ans); } }