Beauty of Array
来源:互联网 发布:多久贴一次面膜知乎 编辑:程序博客网 时间:2024/06/05 21:53
Beauty of Array
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
351 2 3 4 532 3 342 3 3 2
Sample Output
1052138
#include <stdio.h>#include <string.h>#include <stdlib.h>int p[1123456];long long x[112345];int main(void){ int t, n; scanf("%d", &t); while (t--) { scanf("%d", &n); memset(p, 0, sizeof(p)); for (int i = 1; i <= n; i++) scanf("%lld", &x[i]); long long sum = 0; for (int i = 1; i <= n; i++) { sum += (n - i + 1) * (i - p[x[i]]) * x[i]; p[x[i]] = i; } printf("%lld\n", sum); } return 0;}
0 0
- ZOJ3872 Beauty Of Array
- Beauty of Array
- ZOJ 3872Beauty of Array
- ZOJ 3827 Beauty of Array
- ZOJ 3872 Beauty of Array
- ZOJ 3872 Beauty of Array
- ACM-水题 Beauty of Array
- Beauty of Array(ZOJ3872)
- ZOJ 3872 Beauty of Array
- ZOJ 3872 Beauty of Array
- ZOJ-3972 Beauty of Array
- ZOJ 3872 Beauty of Array
- ZOJ3872 Beauty of Array【DP】
- ZOJ3872:Beauty of Array(浙江省赛2015)
- ZOJ 3872 Beauty of Array(数学)
- ZOJ 3872 — Beauty of Array
- [dp] zoj 3872 Beauty of Array
- ZOJ Problem Set - 3872||Beauty of Array
- 2017-04-12 DBA日记,频繁commit导致的log file sync的诊断
- Python+Selenium练习篇之30-获取当前页面全部图片信息
- Java虚拟机-----运行时栈结构
- 算法导论 计数排序
- 垃圾回收基础
- Beauty of Array
- Oracle数据库 ORA-12953/ORA-12952错误相关
- 玩转EXCEL系列-IF函数的使用详解
- android bugreport 解析
- 【吐血推荐】Android 开源项目列表,赶紧收藏吧!
- oj217. Contains Duplicate
- NAT协议
- jdk7中switch 开始支持string 类型
- 爆炒猪舌的方法是什么?