ZOJ 3872 计算对答案的贡献
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<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<cstdio>
- #include<vector>
- #include<string>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #pragma comment(linker, "/STACK:102400000,102400000")
- using namespace std;
- const int N=;
- const int MAX=;
- const int MOD=;
- const int INF=;
- const double EPS=0.00000001;
- typedef long long ll;
- int read()
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- int num[];
- int main()
- {
- int a,i,n,T;
- ll ans;
- scanf("%d", &T);
- while (T--) {
- scanf("%d", &n);
- ans=;
- memset(num,,sizeof(num));
- for (i=;i<=n;i++) {
- scanf("%d", &a);
- ans+=(ll)(i-num[a])*(n-i+)*a;
- num[a]=i;
- }
- printf("%lld\n", ans);
- }
- return ;
- }
代码
ZOJ 3872 计算对答案的贡献的更多相关文章
- UVA 11076 Add Again 计算对答案的贡献+组合数学
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs ...
- UVA 11038 - How Many O's? 计算对答案的贡献
题意: 求[n, m]之间包含0的数字的个数题解:转化为求solve(n) - solve(m-1)的前缀问题 对于求0到n的解,我们举例 n = 25789 对于8这位,让其为0对答案的贡献是 (0 ...
- ZOJ 3872 浙江2015年省赛试题
D - Beauty of Array Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- zoj 3872
D - Beauty of Array Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- DP ZOJ 3872 Beauty of Array
题目传送门 /* DP:dp 表示当前输入的x前的包含x的子序列的和, 求和方法是找到之前出现x的位置(a[x])的区间内的子序列: sum 表示当前输入x前的所有和: a[x] 表示id: 详细解释 ...
- ZOJ 3872 Beauty of Array
/** Author: Oliver ProblemId: ZOJ 3872 Beauty of Array */ /* 需求: 求beauty sum,所谓的beauty要求如下: 1·给你一个集合 ...
- 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 ...
- 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 (The 12th Zhejiang Provincial Collegiate Programming Contest )
对于没有题目积累和clever mind的我来说,想解这道题还是非常困难的,也根本没有想到用dp. from: http://blog.csdn.net/u013050857/article/deta ...
随机推荐
- Android中notifyDataSetInvalidated()和notifyDataSetChanged()有什么区别
看下源码中对于这两个方法 public void notifyDataSetChanged () 该方法内部实现了在每个观察者上面调用onChanged事件.每当发现数据集有改变的情况,或者读取 ...
- Linux安装64位Mysql5.7.22
以安装在/usr/local目录下为例 1.下载安装包地址:https://dev.mysql.com/downloads/file/?id=476936,安装包保存到/usr/local 2.解压: ...
- 【PS切图】前端工程师必备,但又无需精通的一项技能。
前端主要从事一些代码开发工作,PS使用是前端工程师必备,但又无需精通的一项技能. 前端切图四大面板:在“窗口”菜单下开启 1,信息(手动开启)2,字符(手动开启)3,历史记录(手动开启)4,图层(默认 ...
- aggregate和annotate方法使用详解与示例
aggregate和annotate方法的使用场景 Django的aggregate和annotate方法属于高级查询方法,主要用于组合查询.当我们需要对查询集(queryset)的某些字段进行计算或 ...
- sqlserver同一个局域网内,把服务器数据库备份到客户端
1.客户端主机创建网络共享文件夹 2.远程服务器运行: EXEC sp_configure 'show advanced options', 1;-- 允许配置高级选项--配置选项'show adva ...
- LeetCode(64) Minimum Path Sum
题目 Total Accepted: 47928 Total Submissions: 148011 Difficulty: Medium Given a m x n grid filled with ...
- Qt 多语言支持
简介 Qt 多语言支持很强大,很好用. 首先要强调的是程序中需要翻译的字符串最好都用 tr("message") 这种形式,这里的 "message" 就是需要 ...
- mysql和Oracle 备份表
1.SQL Server中,如果目标表存在: insert into 目标表 select * from 原表; 2.SQL Server中,,如果目标表不存在: select * into 目标表 ...
- 餐巾(cogs 461)
[问题描述] 一个餐厅在相继的N天里,第i天需要Ri块餐巾(i=l,2,…,N).餐厅可以从三种途径获得餐巾. (1)购买新的餐巾,每块需p分: (2)把用过的餐巾送到快洗部,洗一块需m天,费用需f分 ...
- [NOIP2006] 提高组 洛谷P1065 作业调度方案
题目描述 我们现在要利用m台机器加工n个工件,每个工件都有m道工序,每道工序都在不同的指定的机器上完成.每个工件的每道工序都有指定的加工时间. 每个工件的每个工序称为一个操作,我们用记号j-k表示一个 ...