Description

Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains 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 <iostream>
using namespace std;
const int maxn=100005;
int n[maxn]; int main()
{
int t;
cin>>t;
while(t--)
{
fill(n,n+maxn,0);
int m;
cin>>m;
long long ans=0,dp=0;
int t;
for(int i=1;i<=m;i++)
{
cin>>t;
dp=(i-n[t])*t+dp;
ans+=dp;
n[t]=i;
}
cout<<ans<<endl;
}
return 0;
}

  

 

Beauty of Array的更多相关文章

  1. DP ZOJ 3872 Beauty of Array

    题目传送门 /* DP:dp 表示当前输入的x前的包含x的子序列的和, 求和方法是找到之前出现x的位置(a[x])的区间内的子序列: sum 表示当前输入x前的所有和: a[x] 表示id: 详细解释 ...

  2. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...

  3. 第十二届浙江省大学生程序设计大赛-Beauty of Array 分类: 比赛 2015-06-26 14:27 12人阅读 评论(0) 收藏

    Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...

  4. ZOJ 3872 Beauty of Array

    /** Author: Oliver ProblemId: ZOJ 3872 Beauty of Array */ /* 需求: 求beauty sum,所谓的beauty要求如下: 1·给你一个集合 ...

  5. Beauty of Array(思维)

    Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integ ...

  6. 2015 浙江省赛 Beauty of Array (思维题)

    Beauty of Array Edward has an array A with N integers. He defines the beauty of an array as the summ ...

  7. ZOJ 3872: Beauty of Array(思维)

    Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...

  8. ZOJ 3872 Beauty of Array【无重复连续子序列的贡献和/规律/DP】

    Edward has an array A with N integers. He defines the beauty of an array as the summation of all dis ...

  9. 浙江省第十二届省赛 Beauty of Array(思维题)

    Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...

随机推荐

  1. nginx前端负载,后端apache获取真实IP设置

    原文链接: nginx前端负载,后端apache获取真实IP设置 参考文献: 前端Nginx,后端Apache获取用户真实IP地址  按照第二种方法设置不成功! 网站最前端是nginx,做的PROXY ...

  2. Chapter 12 外观模式

    外观模式:为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个模式使得这一子系统更加容易使用. 外观模式三个阶段: 首先,在设计初期阶段,应该要有意识的将不同的两个层分离. 其次,在 ...

  3. jsp字段判空

    是对象吧String jsp的写法 <% if(str == null) { %> str is null <% } else { %> str not null <% ...

  4. php 解析url 和parse_url使用

    通过url进行传值,是php中一个传值的重要手段.所以我们要经常对url里面所带的参数进行解析,如果我们知道了url传递参数名称,例如 /index.php?name=tank&sex=1#t ...

  5. Codeforces 435B. Pasha Maximizes

    简单贪心.... B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. DSP连接不上CCS3.3的问题讨论

    环境 操作系统:Win7, 64bit IDE:CCS V3.3 仿真器:SEED XDS510PLUS DSP型号:TMS320C6713GDP(DSP6713) 检查步骤 试着按下复位按键后再点击 ...

  7. 百度编辑器ueditor简单易用

    最近刚刚被分配任务给一个新闻发布,它采用了富文本编辑器.本人也被用于,只是这一次我选择了百度的富文本编辑器ueditor1_4_3-utf8-jsp版. 事实上看ueditor功能非常强大,只是百度的 ...

  8. 编程算法 - 扑克牌的顺子 代码(C)

    扑克牌的顺子 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 从扑克牌中随机抽取5张牌, 推断是不是一个顺子, 即这5张牌是不是连续的. 2~1 ...

  9. Javascript DOM 01 基础篇

    DOM基础   DOM是什么        答:文件对象模型(Document Object Model,简称DOM),DOM可以以一种独立于平台和语言的方式访问和修改一个文档的内容和结构!来自网络 ...

  10. 用来解析,格式化,存储和验证国际电话号码:libphonenumber

    用来解析,格式化,存储和验证国际电话号码:libphonenumber libphonenumber是Google的公共Java.C++和Javascript库用来解析,格式化,存储和验证国际电话号码 ...