CF1119A Ilya and a Colorful Walk
题目地址:CF1119A Ilya and a Colorful Walk
\(O(n^2)\) 肯定过不掉
记 \(p_i\) 为从下标 \(1\) 开始连续出现 \(i\) 的个数
那么对于每一个 \(i\) ,在 \(i\) 之前离 \(i\) 最远的与 \(a_i\) 不同的数的距离显然为 \(i-p_{a_i}-1\) 。
取 \(max\) 就好了
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 6;
int n, a[N], p[N], ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
if (p[a[i]] == i - 1) p[a[i]] = i;
for (int i = 1; i <= n; i++)
ans = max(ans, i - p[a[i]] - 1);
cout << ans << endl;
return 0;
}
CF1119A Ilya and a Colorful Walk的更多相关文章
- CF1119A Ilya and a Colorful Walk 题解
Content 有一个长度为 \(n\) 的数组 \(a_1,a_2,a_3,...,a_n\),试求出两个不相等的数之间的距离的最大值. 数据范围:\(3\leqslant n\leqslant 3 ...
- 题解 CF1119A 【Ilya and a Colorful Walk】
此题就是:给你一个数组,让你找出两个不同的元素,并让它们的下标差距最大. 思路:从2到n,如果与1不同,记录距离,与原数比较,取大. 从1到n-1,如果与n不同,记录距离,与原数比较,取大. AC代码 ...
- CF1119 Global Round 2
CF1119A Ilya and a Colorful Walk 这题二分是假的.. \(1,2,1,2,1\) 有间隔为 \(3\) 的,但没有间隔为 \(2\) 的.开始被 \(hack\) 了一 ...
- Codeforces Global Round 2 Solution
这场题目设置有点问题啊,难度:Div.2 A->Div.2 B->Div.2 D->Div.2 C->Div.2 D->Div.1 D-> Div.1 E-> ...
- Codeforces Global Round 2部分题解
传送门 好难受啊掉\(rating\)了-- \(A\ Ilya\ and\ a\ Colorful\ Walk\) 找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不 ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Global Round 2
A - Ilya and a Colorful Walk CodeForces - 1119A Ilya lives in a beautiful city of Chordalsk. There a ...
- python os.walk()
os.walk()返回三个参数:os.walk(dirpath,dirnames,filenames) for dirpath,dirnames,filenames in os.walk(): 返回d ...
- LYDSY模拟赛day1 Walk
/* 依旧考虑新增 2^20 个点. i 只需要向 i 去掉某一位的 1 的点连边. 这样一来图的边数就被压缩到了 20 · 2^20 + 2n + m,然后 BFS 求出 1 到每个点的最短路即可. ...
随机推荐
- SQL Server中NULL的一个测试
我们都知道SQL Server中NULL是一个很特殊的存在,因为NULL不会等于任何值,且NULL也不会不等于任何值.对于NULL我们只能使用IS或IS NOT关键字来进行比较. 我们先来看看下面一个 ...
- vue的一些基本知识
配置webpack及vue脚手架工具: vue-cli 2 npm install webpack webpack-cli -g npm install vue-cli -g 搭建脚手架 vue ...
- JavaScript验证输入的字符是否包含表情
以下是验证代码: function isEmojiCharacter(substring) { for ( var i = 0; i < substring.length; i++) { var ...
- System.nanoTime与System.currentTimeMillis的区别(转)
原文地址:http://blog.csdn.net/dliyuedong/article/details/8806868 平时产生随机数时我们经常拿时间做种子,比如用System.currentTim ...
- MyBatis 传List参数 nested exception is org.apache.ibatis.binding.BindingException: Parameter 'idList' not found.
在MyBatis传入List参数时,MyBatis报错:nested exception is org.apache.ibatis.binding.BindingException: Paramete ...
- vscode在vue-cli中按照ESlint自动格式化代码
先安装 1 npm i -S eslint-plugin-vue .eslintrc下 1 2 3 "plugins": [ "vue" ] vscod ...
- MySQL系列:数据库基本操作(1)
1. 登录数据库 mysql -h localhost -u root -p 2. 数据库基本操作 2.1 查看数据库 mysql> SHOW DATABASES; +------------- ...
- 阿里云短信服务bug
接入阿里云短信服务,在springboot中写测试方法,执行到 IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou ...
- ListView与RecyclerView对比浅析——缓存机制
https://www.jianshu.com/p/193fb966e954 一,背景 RecyclerView是谷歌官方出的一个用于大量数据展示的新控件,可以用来代替传统的ListView,更加强大 ...
- Django之ContentType组件
一.理想表结构设计 1.初始构建 1. 场景刚过去的双12,很多电商平台都会对他们的商品进行打折促销活动的,那么我们如果要实现这样的一个场景,改如何设计我们的表? 2. 初始表设计 注释很重要,看看吧 ...