设为首页 加入收藏

TOP

The 12th Zhejiang Provincial Collegiate Programming Contest(部分)(四)
2015-11-21 01:03:50 来源: 作者: 【 】 浏览:11
Tags:The 12th Zhejiang Provincial Collegiate Programming Contest (部分
ains an integer N (1 <= N <= 100000), which indicates the size of the array. The next line contains N positive integers separated by spaces. Every integer is no larger than 1000000.

Output

For each case, print the answer in one line.

Sample Input

3
5
1 2 3 4 5
3
2 3 3
4
2 3 3 2

Sample Output

105
21
38





#include
         
          
#include
          
            #include
           
             #include
            
              #include
             
               #include
              
                using namespace std; int a[100010]; int v[1001000]; int main() { int T; scanf("%d",&T); while(T--) { long long int n; memset(v,0,sizeof(v)); long long int sum = 0; int k = 1; scanf("%lld",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum += (n-i+1)*k*a[i]; if(v[a[i]]) { sum -= v[a[i]] * (n-i+1)*a[i]; } v[a[i]] = i; k++; } printf("%lld\n",sum); } return 0; } 
              
             
            
           
          
         



首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇算法学习 - 动态规划(DP问题)(C++) 下一篇C++ 的 const和const_cast

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: