当前位置:网站首页>Beauty Values
Beauty Values
2022-08-09 10:50:00 【天T.】
题目链接:题目地址
题目描述:
Gromah and LZR have entered the second level. There is a sequence a1,a2,a3…an on the wall.
There is also a note board saying “the beauty value of a sequence is the number of different elements in the sequence”.
LZR soon comes up with the password of this level, which is the sum of the beauty values of all successive subintervals of the sequence on the wall.
Please help them determine the password!
输入描述:
The first line contains one positive integer n , denoting the length of the sequence.
The second line contains n positive integers a1,a2,a3…an denoting the sequence.
1<=ai<=n<=100000
输出描述:
Print a non-negative integer in a single line, denoting the answer.
输入
4
1 2 1 3
输出
18
说明
The beauty values of subintervals [1,1], [2,2], [3,3], [4,4] are all 1
.
The beauty values of subintervals [1,2], [1,3], [2,3], [3,4] are all 2
.
The beauty values of subintervals [1,4], [2,4] are all 3
.
As a result, the sum of all beauty values are 1×4+2×4+3×2=18.
中文翻译:
Gromah和LZR进入了第二层。有一个序列a1 a2 a3…an一个在墙上。
还有一个留言板上写着“一个序列的美值是序列中不同元素的数量”。
LZR很快就会给出这个级别的密码,它是墙上的序列的所有连续子区间的美丽值的总和。
请帮助他们确定密码!
#include<iostream>
using namespace std;
typedef long long ll;
long long ans;
int n,a[100005],book[100005];
/*题目中的例子:1213 [1,2][2,2][3,3][4,4]--->1---是指1到1的区间,不同的数只有1;2到2区间,不同的数只有2.... [1,2][1,3][2,3][3,4]---->2---1到2下标区间,不同的数有1,2,有2个;1到3下标区间,不同的数有1,2,有2个;2到3下标区间,不同的数有2,1,有2个;3到4下标区间,不同的数有1,3,有2个 [1,4][2,4]--->3---1到4下标区间,不同的数有1,2,3,有3个;2到4下标区间,不同的数有2,1,3,有3个 */
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++){
if(book[a[i]]==0){
ans+=(ll)(n-i+1)*i;
}else{
ans+=(ll)(n-i+1)*(i-book[a[i]]);
}
book[a[i]]=i;//有多少重复的数
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- 1005 Spell It Right (20分)
- faster-rcnn中的RPN原理
- unix环境编程 第十四章 14.8 存储映射I/O
- torch.cat()函数的官方解释,详解以及例子
- 力扣(LeetCode)220. 存在重复元素 III(2022.08.08)
- Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings
- 乘积量化(PQ)
- 通过Doc在MySQL数据库中建表
- autogluon安装,使用指南,代码
- 强化学习 (Reinforcement Learning)
猜你喜欢
史上最小白之《Word2vec》详解
cesium加载地图
华为VRRP+MSTP联动接口检测实验案例
想了解API接口,这一篇就够了
机器学习-逻辑回归(logistics regression)
The common problems in laptops, continuously updated
Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 1 Find programs in the PATH
PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization Paper Reading
CSDN的markdown编辑器语法完整大全
Solve the ali cloud oss - the original 】 【 exe double-click response can't open, to provide a solution
随机推荐
依赖注入(Dependency Injection)框架是如何实现的
linux mysql操作的相关命令
numpy库中的函数 bincount() where() diag() all()
The torch. The stack () official explanation, explanation and example
Unix Environment Programming Chapter 15 15.3 Functions popen and pclose
unix环境编程 第十五章 15.10 POSIX信号量
1007 Maximum Subsequence Sum (25分)
How tall is the B+ tree of the MySQL index?
OpenSSF's open source software risk assessment tool: Scorecards
Quartz分布式实现
The common problems in laptops, continuously updated
tensor.eq() tensor.item() tensor.argmax()
非科班毕业生,五面阿里:四轮技术面+HR一面已拿offer
RPN principle in faster-rcnn
MySQL外键在数据库中的作用
支付宝小程序的接入
信息系统项目的十大管理
Preparation for gold three silver four: how to successfully get an Ali offer (experience + interview questions + how to prepare)
kubernetes中不可见的OOM
笔记本电脑使用常见问题,持续更新