Beauty of Array
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的更多相关文章
- DP ZOJ 3872 Beauty of Array
题目传送门 /* DP:dp 表示当前输入的x前的包含x的子序列的和, 求和方法是找到之前出现x的位置(a[x])的区间内的子序列: sum 表示当前输入x前的所有和: a[x] 表示id: 详细解释 ...
- 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 ...
- 第十二届浙江省大学生程序设计大赛-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. ...
- ZOJ 3872 Beauty of Array
/** Author: Oliver ProblemId: ZOJ 3872 Beauty of Array */ /* 需求: 求beauty sum,所谓的beauty要求如下: 1·给你一个集合 ...
- Beauty of Array(思维)
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integ ...
- 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 ...
- ZOJ 3872: Beauty of Array(思维)
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...
- 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 ...
- 浙江省第十二届省赛 Beauty of Array(思维题)
Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...
随机推荐
- Android百度地图之显示地图
添加地图显示 一.在百度官网下载相关的SDK (网址:http://developer.baidu.com/map/sdkandev-download.htm) 解压下载好的BaiduMap_Andr ...
- c语言中malloc realloc 和calloc的联系与区别
(1)C语言跟内存分配方式 <1>从静态存储区域分配. 内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量.static变量.<2> ...
- svn笔记4属性Properties
我们已经详细讲述了Subversion存储和检索版本库中不同版本的文件和目录的细节,并且用了好几个章节来论述这个工具的基本功能.如果对于版本化的支持到此为止,从版本控制的角度来看Subversion已 ...
- 侧滑UI
1.视图 activity_main.xml <com.zyhui.cehua.SlidingMenu xmlns:android="http://schemas.android.co ...
- iOS开发中xib和Storyboard中需要注意的事项
使用xib注意事项: 1.只有自带view的控件才可以使用xib,因为它本身就是一个view 2.在使用可视化控件添加属性(代码)时候,如果删除了属性代码,一定要在xib上解除关联(不然会崩溃) 3. ...
- 如何将一个Jsp网站打包发布(发布为War文件)
链接地址:http://blog.csdn.net/luohuijun619/article/details/4867131 版权声明:本文为博主原创文章,未经博主允许不得转载. 网站做完后,并不是直 ...
- 利用ant的javac任务来编译java程序
<?xml version="1.0" encoding="UTF-8"?> <project name="javaTest&quo ...
- LVS--什么是LVS?
1.什么是LVS? 首先简单介绍一下LVS (Linux Virtual Server)到底是什么东西,其实它是一种集群(Cluster)技术,采用IP负载均衡技术和基于内容请求分发技术.调度器具有很 ...
- java--创建多线程两种方法的比较
[通过继承Thread] 一个Thread对象只能创建一个线程,即使它调用多次的.start()也会只运行一个的线程. [看下面的代码 & 输出结果] package Test; class ...
- 浅谈MySql的存储引擎(表类型) (转)
什么是MySql数据库 通常意义上,数据库也就是数据的集合,具体到计算机上数据库可以是存储器上一些文件的集合或者一些内存数据的集合. 我们通常说的MySql数据库,sql server数据库等等其实是 ...