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的更多相关文章

  1. 2019牛客暑期多校训练营(第八场)B Beauty Values && C CDMA

    B题题意: 题目 给你n个数,让你把这一个序列中的所有子区间的Beauty Values加起来,Beauty Values是子区间内有几个不同的数 题解: 肯定不会是暴力,所以我们就要在各元素的位置上 ...

  2. 2019牛客多校B Beauty Values——思维题

    题目 求所有子区间中不同元素之和. 分析 枚举相邻的相同数字形成的区间,计算它是哪些区间的子区间,每次有-1的贡献,将其从总贡献中减去. #include<bits/stdc++.h> u ...

  3. 2019牛客暑期多校训练营(第八场) - B - Beauty Values - 水题

    https://ac.nowcoder.com/acm/contest/888/B 实际上的确是个水题,写个小数据找个规律看看,所谓不同度,其实就是依次插入每个元素后,各种元素出现的最后位置的坐标求和 ...

  4. 牛客多校第八场 B Beauty Values 水题

    题意: 给定一个序列,问你子区间中不同数字数量,在所有子区间中之和为多少. 题解: 统计每个数字在多少个区间中出现即可.对于每个数字,直接枚举左右端点. 注意去重,因此要记录每个数字上一次出现在哪里, ...

  5. cf #365b 巧妙的统计

     Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. 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 ...

  7. cf703B Mishka and trip

    B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input  standard ...

  8. 暑假练习赛 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 ...

  9. 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 ...

随机推荐

  1. Go语言入门篇-高级数据类型

    一.数组类型 二.切片类型 切片的更多操作方法 示例: 三.字典类型 四.通道类型 示例: 通道的更多种类 示例: 五.函数 示例: 六.结构体和方法 示例: 七.接口 八.指针 示例: mooc

  2. 期货、股指期权、ETF期权

    期货与期权: 期权是指一种合约,该合约赋予持有人在某一特定日期或该日之前的任何时间以固定价格购进或售出某种资产的权利. 期货是标准化的合约,赋予参与者在未来的某个时间点以约定好的一个价格去买入或者卖出 ...

  3. Mac-peizhi

    ##1-JMeter4export JMETER_HOME=/Users/wulei/softwares/installedsoftwares/apache-jmeter-4.0export CLAS ...

  4. [转帖]功耗降50%,性能升35%!三星3nm GAA 2021年量产

    功耗降50%,性能升35%!三星3nm GAA 2021年量产 http://www.chinaflashmarket.com/Instructor 在三星晶圆代工技术论坛(Samsung Found ...

  5. STM32f103软件复位

    参考博客: http://bbs.21ic.com/icview-1251690-1-1.html stm32f103rct 软件复位函数: 在core_cm3.h文件 static __INLINE ...

  6. Apache 强制SSL访问

    RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R ...

  7. Scrapy 教程(九)-日志系统

    最新版本的 scrapy 已经废弃了 scrapy.log 的使用,赞成显示调用python标准日志记录. Python 内建日志系统 import logging ### python 内建 log ...

  8. Linux :环境变量设置和本地变量加载

    bash: 全局变量: /etc/profile,  /etc/profile.d/*,  /etc/bashrc 个人变量: ~/.bash_profile,   ~/.bashrc bash运行方 ...

  9. FFmpeg SDK开发模型之中的一个:解码器

    简单介绍 本例解说了怎样使用ffmpeg SDK解码媒体文件: 參考源代码是ffmpeg 自带的apiexample.c 一.源代码#include <stdlib.h>#include ...

  10. Redis数据结构&命令手册

    Redis数据结构&命令手册 Redis数据结构 Redis可以存储键与5种不同数据结构之间的映射,这五种数据结构类型分别为STRING(字符串).LIST(列表).SET(集合).HASH( ...