当前位置:网站首页>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;
}
边栏推荐
- MySQL外键在数据库中的作用
- Create a table in a MySQL database through Doc
- pip common commands and changing source files
- arcgis制图之天地图符号样式配置
- 支付宝小程序的接入
- The complete grammar of CSDN's markdown editor
- Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings
- 1009 Product of Polynomials C语言多项式乘积(25分)
- 多商户商城系统功能拆解26讲-平台端分销设置
- numpy库中的函数 bincount() where() diag() all()
猜你喜欢
OpenSSF's open source software risk assessment tool: Scorecards
性能测试(05)-表达式和业务关联-json关联
Netscope: Online visualization tool for neural network structures
【原创】解决阿里云oss-browser.exe双击没反应打不开,提供一种解决方案
Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings
activemq message persistence
Netscope:神经网络结构在线可视化工具
人物 | 从程序员到架构师,我是如何快速成长的?
彻底理解工厂模式
机器学习--朴素贝叶斯(Naive Bayes)
随机推荐
String类型的字符串对象转实体类和String类型的Array转List
遇到恶意退款不用怕,App 内购买项目的退款通知现已可用
性能测试(04)-表达式和业务关联-JDBC关联
编解码(seq2seq)+注意机制(attention) 详细讲解
The common problems in laptops, continuously updated
为什么组合优先于继承
Quartz的理解
Pyhton实战汇总篇
RPN principle in faster-rcnn
深度学习--神经网络(基础讲解)
Unix Environment Programming Chapter 15 15.7 Message Queuing
AQS同步组件-ForkJoin、BlockingQueue阻塞队列解析和用例
深度学习--自编码器(AutoEncoder)
[华为云在线课程][SQL语法分类][数据操作][学习笔记]
通过Doc在MySQL数据库中建表
性能测试(03)-JDBC Request
数据存储:对dataframe类,使用to_csv()将中文数据写入csv文件
聚类了解
【原创】VMware Workstation实现Openwrt软路由功能,非ESXI,内容非常详细!
torch.stack()的官方解释,详解以及例子