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. Java类加载器总结网址

    http://blog.csdn.net/gjanyanlig/article/details/6818655

  2. sql limit order by and where

    1 sql limit limit size,返回前size行. limit offset , size,返回offset开始的size行,offset从0行开始. 2 sql limit with ...

  3. uboot常用命令

    一. 常用简单命令 1.1. help命令 a. 帮助查看其他命令的使用方法,类型linux下man b. 示例: help help x210 # help help help [command . ...

  4. Tarjan水题系列(1):草鉴定Grass Cownoisseur [USACO15JAN]or[luogu P3119]

    题目如下: 约翰有n块草场,编号1到n,这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可能多的草场去品尝牧草. 贝西总是从1号草场出发,最后回到1号草场.她想经过尽可能多的草场,贝 ...

  5. HBase Shell 的常用操作总结

      1,创建表:create 't1','f1','f2','f3'                   #-------t1是表名,f1,f2,f3是列族名   2,查看所有的表:list   3, ...

  6. 关于使用iframe的父子页面进行简单的相互传值

    当一个页面使用了iframe作为嵌套时,如何想要将父页面的数据传给iframe子页面,那iframe所指向的呢个子页面是怎么获取呢,又或者子页面的数据要给父页面使用,那么父页面又如何获取子页面的数据呢 ...

  7. css发展过程

    https://www.cnblogs.com/dashnowords/p/9460722.html

  8. php 爬虫爱奇艺 视频、内容

    ,][];   ][];   ][]);   ][]);   ]);    ][]; ][]; ][])) {     ][];   }][])) {     ][];   }   ][];   ; ...

  9. vue.js table组件封装

    table组件 和 分页组件来自iview,在这里我根据公司业务再次做了一次封装,使用slot进行内容分发,可以随意放置input输入框和button按钮 ,再使用props向子组件传递参数,使用em ...

  10. Spring Boot 支持https

    1. 生成key JDK下 keytool -genkeypair -alias mySSL -keyalg RSA -keystore E:\tomcat.key 其中-alias是证书的别名,RS ...