ZOJ 3872 浙江2015年省赛试题
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
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
你求这n个数的子序列中不算重复的数的和,
比如第二个样例他的子序列就是
{2},{2,3},{2,3,3},{3},{3,3},{3};
但每个子序列中重复的元素不被算入,
所以他们的总和就是2+5+5+3+3+3=21;
#include <cstdio>
#include <cstring>
#include <algorithm>
#include<math.h>
using namespace std;
#define max_v 100005
typedef long long LL;
LL dp[max_v];
LL sum;
LL num[max_v];
LL v[max_v];
void init()
{
sum=;
memset(dp,,sizeof(dp));
memset(num,,sizeof(num));
memset(v,,sizeof(v));
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
init();
for(int i=;i<=n;i++)
{
scanf("%lld",&num[i]);
}
for(int i=;i<=n;i++)
{
dp[i]=dp[i-]+(i-v[num[i]])*num[i];
sum+=dp[i];
v[num[i]]=i;
}
printf("%lld\n",sum);
}
return ;
}
/* 这个题的意识就是给你n个数,
你求这n个数的子序列中不算重复的数的和,
比如第二个样例他的子序列就是
{2},{2,3},{2,3,3},{3},{3,3},{3};
但每个子序列中重复的元素不被算入,
所以他们的总和就是2+5+5+3+3+3=21; dp[i]: 以第i个数结尾的所有子序列的和是多少。 那么这样我们就有了一个很简单的转移方法: dp[i] = dp[i-1] + x[i] * (i - v[num[i]]); v表示的是num[i]这个数字上一次出现在哪个位置, 这样可以确保不会重复计算 */
ZOJ 3872 浙江2015年省赛试题的更多相关文章
- 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
D - Beauty of Array Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- 思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys
题目传送门 /* 题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达 思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排 ...
- 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT
2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...
- 2015北京网络赛 J Scores bitset+分块
2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...
- 2015北京网络赛 Couple Trees 倍增算法
2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道. 解法来自 q ...
- 浙江理工2015.12校赛-A
孙壕请一盘青岛大虾呗 Time Limit: 5 Sec Memory Limit: 128 MB Submit: 577 Solved: 244 Description 话说那一年zstu与gdut ...
- 2015年第六届蓝桥杯JavaB组省赛试题解析
题目及解析如下: 题目大致介绍: 第一题到第三题以及第六题.第七题是结果填空,方法不限只要得到最后结果就行 第四题和第五题是代码填空题,主要考察算法基本功和编程基本功 第八题到第十题是编程题,要求编程 ...
随机推荐
- 通过ifrmae异步下载文档
//通过ifrmae异步下载文档 function iframeGetFile(opts) { var defaultOpts = { filePath: '', onload: function ( ...
- [转]关于浏览器css选择器性能优化
作为一个前端开发, 我觉得很有必要了解浏览器对css选择器的解析,因为这个关系到页面的渲染,高效的方式.避开开销大的方式这些无疑为网站加载缩短了时间. 最近在新的项目中陷入了一个误区,也是出于对jqu ...
- Keras vs. PyTorch in Transfer Learning
We perform image classification, one of the computer vision tasks deep learning shines at. As traini ...
- samba 使用tips
安装: 推荐使用新立德包管理器安装 SAMBA配置文件: /etc/samba/smb.conf Samba服务器的启动与关闭: sudo /etc/init.d/smbd start ubuntu访 ...
- Linux服务器安装JDK运行环境教程
小Alan过些天可能就要去上海出差了,出差干啥?当然是部署项目上线咯!所以呢必须自己学会在Linux服务上面安装部署项目运行环境的啦!今天先跟大家聊聊最基本的jdk运行环境部署安装,后续再跟大家分享一 ...
- selenium模拟鼠标操作
Selenium提供了一个类ActionChains来处理模拟鼠标事件,如单击.双击.拖动等. 基本语法: class ActionChains(object): """ ...
- asp.net MVC4 框架揭秘 读书笔记系列1
1.1 传统MVC 名词解释 Autonomous View. AV. 自制视图 GUI图形用户界面(Graphical User Interface,简称 GUI,又称图形用户接口)是指采用图形方式 ...
- [翻译] USING GIT IN XCODE [6] 在XCODE中使用GIT[6]
USING GIT IN XCODE KEEPING IN SYNC WITH REMOTE REPOSITORIES As you make changes in your local workin ...
- 引用js文件
在子模板里引用js文件的时候,需要把相应的.js文件放到static目录下,如引用static/jQuery/index.js文件: {% extends "base.html" ...
- Fiddler下Firefox提示“您的连接并不安全”的解决办法
一.版本信息 Firefox 最新版本V46.0.1 Fiddler 最新版本V4.6.2.3 二.错误信息 开启fiddlers的https协议捕获的方法,百度上可以查到不再赘述,直接放张图(Too ...