题:https://codeforces.com/contest/1082/problem/E

题意:给出n个数和一个数c,只能操作一次将[L,R]之间的数+任意数,问最后该序列中能存在最多多少个c

分析:考虑dp,dp[i]表示将该位置染成c的答案,那么将该颜色染成c肯定要和其他和这个位置值相同的位置尝试染一染,这个尝试就是dp的取max值,这里采用的是遍历到某一个值就查询之前出现的最近的位置,然后尝试,因为往后递推这样的关系就会被连起来,接着就是预处理一下前后缀c的个数。

#include<bits/stdc++.h>
using namespace std;
const int M=5e5+;
int pre[M],suf[M],dp[M],a[M],las[M];
int main(){
int n,c;
scanf("%d%d",&n,&c);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
pre[i]=pre[i-];
if(a[i]==c)
pre[i]++;
}
for(int i=n;i>=;i--){
suf[i]=suf[i+];
if(a[i]==c)
suf[i]++;
}
int ans=;
for(int i=;i<=n;i++){
dp[i]=pre[i-]+; if(las[a[i]])
dp[i]=max(dp[i],dp[las[a[i]]]+);
ans=max(ans,dp[i]+suf[i+]);
las[a[i]]=i;
}
printf("%d\n",ans);
}

Educational Codeforces Round 55 (Rated for Div. 2)E的更多相关文章

  1. Educational Codeforces Round 55 (Rated for Div. 2) C. Multi-Subject Competition 【vector 预处理优化】

    传送门:http://codeforces.com/contest/1082/problem/C C. Multi-Subject Competition time limit per test 2 ...

  2. Educational Codeforces Round 55 (Rated for Div. 2) A/B/C/D

    http://codeforces.com/contest/1082/problem/A WA数发,因为默认为x<y = = 分情况讨论,直达 or x->1->y  or  x-& ...

  3. Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies 【贪心 】

    传送门:http://codeforces.com/contest/1082/problem/B B. Vova and Trophies time limit per test 2 seconds ...

  4. Codeforces 1082 C. Multi-Subject Competition-有点意思 (Educational Codeforces Round 55 (Rated for Div. 2))

    C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. Codeforces 1082 A. Vasya and Book-题意 (Educational Codeforces Round 55 (Rated for Div. 2))

    A. Vasya and Book time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency

    E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...

  7. Educational Codeforces Round 55 (Rated for Div. 2):D. Maximum Diameter Graph

    D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成 ...

  8. Educational Codeforces Round 55 (Rated for Div. 2):C. Multi-Subject Competition

    C. Multi-Subject Competition 题目链接:https://codeforces.com/contest/1082/problem/C 题意: 给出n个信息,每个信息包含专业编 ...

  9. Educational Codeforces Round 55 (Rated for Div. 2)

    D. Maximum Diameter Graph 题意 给出每个点的最大度,构造直径尽可能长的树 思路 让度数大于$1$的点构成链,考虑是否能在链的两端加度为$1$的点 代码 #include &l ...

随机推荐

  1. python的库有多少个?python有多少个模块?

    这里列举了大概500个左右的库: !   Chardet字符编码探测器,可以自动检测文本.网页.xml的编码. colorama主要用来给文本添加各种颜色,并且非常简单易用. Prettytable主 ...

  2. Session简单介绍

    Session 会话 , Session是基于Cookie的一种会话机制. Cookie是服务器返回一小份数据给客户端,并且存放在客户端上. Session是,数据存放在服务器端. 常用API //得 ...

  3. 【机器学习实战学习笔记(1-2)】k-近邻算法应用实例python代码

    文章目录 1.改进约会网站匹配效果 1.1 准备数据:从文本文件中解析数据 1.2 分析数据:使用Matplotlib创建散点图 1.3 准备数据:归一化特征 1.4 测试算法:作为完整程序验证分类器 ...

  4. Django学习笔记〇四——数据库ORM的使用(有待修改)

    Django框架基本上都是要和数据库结合使用的,我在以前讲过SQLAlchemy框架的使用,Django支持的不是SQLAlchemy,但是也内嵌了ORM框架,可以不需要直接面对数据库编程,而可以通过 ...

  5. css 居中布局方案

    position(transform css3  有些浏览器不兼容) <article id="one"> <section id="section&q ...

  6. 强制浏览器以IE8版本运行

    做为一个开发人员,经常被要求前端页面兼容ie8及以上,所以有时候我们希望ie默认以ie8的版本打开我们的页面. 1.“文档模式”: 在html页面中加入类似下面的代码: <meta http-e ...

  7. POJ 1469:COURSES

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19458   Accepted: 7658 Descript ...

  8. C++优先队列详解

    转自csdn的文章,仅作为学习笔记.原文链接:https://blog.csdn.net/weixin_36888577/article/details/79937886 普通的队列是一种先进先出的数 ...

  9. JetBrains系列-插件

       插件官网:http://plugins.jetbrains.com   注意:网站有时不稳定,会造成打不开,属正常现象或许下一秒就好了,可以选择去git等方式下载 1.安装说明:   打开fil ...

  10. Delphi生成即调用带窗体的Dll

    library frmDll; { Important note about DLL memory management: ShareMem must be the first unit in you ...