Beauty Values
题意:给$n$个数,
定义它的Beauty Values为所有连续子区间的(区间长度*区间内不同数字的数目)求和
求Beauty Values
A[i]数组表示数字i最近一次出现在什么时候,增加一个数字i,A[i]之前引起的只是区间长度的变化,数字种类没有增加,
dp[i]记录i和i-1之间的ans差
#include<bits/stdc++.h>
using namespace std;
int A[];
//int B[100004];
typedef long long ll;
ll dp[];
ll ans=,t=;
int n;
int main()
{
scanf("%d",&n);
int x;
for(int i=;i<=n;i++){
scanf("%d",&x);
if(A[x]==){
ans+=(dp[i-]+i);
dp[i]=ans-t;
A[x]=i;
t=ans;
}else{
ans+=dp[i-]+i-A[x];
dp[i]=ans-t;
A[x]=i;
t=ans;
}
}
cout<<ans<<'\n';
}
Beauty Values的更多相关文章
- 2019牛客暑期多校训练营(第八场)B Beauty Values && C CDMA
B题题意: 题目 给你n个数,让你把这一个序列中的所有子区间的Beauty Values加起来,Beauty Values是子区间内有几个不同的数 题解: 肯定不会是暴力,所以我们就要在各元素的位置上 ...
- 2019牛客多校B Beauty Values——思维题
题目 求所有子区间中不同元素之和. 分析 枚举相邻的相同数字形成的区间,计算它是哪些区间的子区间,每次有-1的贡献,将其从总贡献中减去. #include<bits/stdc++.h> u ...
- 2019牛客暑期多校训练营(第八场) - B - Beauty Values - 水题
https://ac.nowcoder.com/acm/contest/888/B 实际上的确是个水题,写个小数据找个规律看看,所谓不同度,其实就是依次插入每个元素后,各种元素出现的最后位置的坐标求和 ...
- 牛客多校第八场 B Beauty Values 水题
题意: 给定一个序列,问你子区间中不同数字数量,在所有子区间中之和为多少. 题解: 统计每个数字在多少个区间中出现即可.对于每个数字,直接枚举左右端点. 注意去重,因此要记录每个数字上一次出现在哪里, ...
- cf #365b 巧妙的统计
Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #365 (Div. 2) B 前缀和
B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf703B Mishka and trip
B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 暑假练习赛 003 F Mishka and trip
F - Mishka and trip Sample Output Hint In the first sample test: In Peter's first test, there's on ...
- C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列
C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
随机推荐
- Grafana配置文件
配置文件位置 /usr/local/opt/grafana/share/grafana/default.ini /usr/local/etc/grafana/grafana.ini 配置文件调用顺序 ...
- python+selenium下弹窗alter对象处理01
alt.accept() : 等同于单击“确认”或者“OK” alt.dismiss() : ...
- 蚁群算法解决TSP问题
代码实现 运行结果及参数展示 alpha=1beta=5 rho=0.1 alpha=1beta=1rho=0.1 alpha=0.5beta=1rho=0.1 概念蚁群算法(AG)是一种模拟蚂蚁觅 ...
- P1507NASA食物
这道题是一个01背包的延伸题,只要透彻理解了,就不难了. 这个题有两个T,一个是体积一个是质量,所以这时候我们必须要加一个for了,同时要优化空间(三维降二维),然后用f[j][k]来表示当体积为j, ...
- Luogu P5444 [APIO2019]奇怪装置
题目 这种题目看上去就是有循环节的对吧. 在考场上,一个可行的方式是打表. 现在我们手推一下这个循环节. 记函数\(f(t)=(((t+\lfloor\frac tB\rfloor)\%A),(t\% ...
- [LeetCode] 47. 全排列 II
题目链接 : https://leetcode-cn.com/problems/permutations-ii/ 题目描述: 给定一个可包含重复数字的序列,返回所有不重复的全排列. 示例: 输入: [ ...
- 6-3 如何解析简单的XML文档
元素节点.元素树 >>> from xml.etree.ElementTree import parse >>> help(parse) Help on funct ...
- 攻防世界--when_did_you_born5
测试文件:https://adworld.xctf.org.cn/media/task/attachments/24937e95ca4744818feebe82ab96902d 1.准备 root@l ...
- Optional接口简记
@Data public class Employee { private String name; } @Data public class Company { private String nam ...
- 如何让form2中的数据源,显示在form1的dataGridView控件中呢????
定义一个static的静态变量,即可全局访问