CF1436E.Complicated Computations
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In this problem MEX of a certain array is the smallest positive integer not contained in this array.
Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes up with a new problem involving MEX every day, including today.
You are given an array a of length n. Lesha considers all the non-empty subarrays of the initial array and computes MEX for each of them. Then Lesha computes MEX of the obtained numbers.
An array b is a subarray of an array a, if b can be obtained from a by deletion of several (possible none or all) elements from the beginning and several (possibly none or all) elements from the end. In particular, an array is a subarray of itself.
Lesha understands that the problem is very interesting this time, but he doesn't know how to solve it. Help him and find the MEX of MEXes of all the subarrays!
本题中,某个数组的 MEX(最小不存在正整数)是指未出现在该数组中的最小正整数。
这个定义人尽皆知,Lesha 当然也清楚。但 Lesha 十分喜爱 MEX,因此他每天都会构思一个与 MEX 相关的新问题——今天也不例外。
给定一个长度为 n 的数组 a。Lesha 考察原数组的所有非空子数组,并对每个子数组分别计算其 MEX。随后,Lesha 再对所有这些得到的 MEX 值计算一次 MEX。
若数组 b 可通过对数组 a 删除开头若干个(可能为零个或全部)元素、以及结尾若干个(可能为零个或全部)元素而得到,则称 b 是 a 的一个子数组。特别地,一个数组是其自身的子数组。
Lesha 意识到这次的问题非常有趣,但他却不知如何求解。请帮助他,求出所有子数组的 MEX 值所构成集合的 MEX!
输入格式
The first line contains a single integer n (1≤n≤105) — the length of the array.
The next line contains n integers a1,a2,…,an (1≤ai≤n) — the elements of the array.
第一行包含一个整数 n(1≤n≤105)—— 数组的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)—— 数组的元素。
输出格式
Print a single integer — the MEX of MEXes of all subarrays.
输出一个整数——所有子数组的 MEX 值所组成的集合的 MEX。
输入输出样例
输入#1
3 1 3 2
输出#1
3
输入#2
5 1 4 3 1 2
输出#2
6
输入解题思路,AI测评打分。不知道怎么写?