传统题 4000ms 1024MiB

E - Mex Min

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

E - Mex Min

Score : $500$ points

Problem Statement

Let us define $\mathrm{mex}(x_1, x_2, x_3, \dots, x_k)$ as the smallest non-negative integer that does not occur in $x_1, x_2, x_3, \dots, x_k$.
You are given an integer sequence of length $N$: $A = (A_1, A_2, A_3, \dots, A_N)$.
For each integer $i$ such that $0 \le i \le N - M$, we compute $\mathrm{mex}(A_{i + 1}, A_{i + 2}, A_{i + 3}, \dots, A_{i + M})$. Find the minimum among the results of these $N - M + 1$ computations.

Constraints

  • $1 \le M \le N \le 1.5 \times 10^6$
  • $0 \le A_i \lt N$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 A3A_3 \dots ANA_N

Output

Print the answer.


3 2
0 0 1
1

We have:

  • for $i = 0$: $\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \mathrm{mex}(0, 0) = 1$
  • for $i = 1$: $\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \mathrm{mex}(0, 1) = 2$

Thus, the answer is the minimum among $1$ and $2$, which is $1$.


3 2
1 1 1
0

We have:

  • for $i = 0$: $\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \mathrm{mex}(1, 1) = 0$
  • for $i = 1$: $\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \mathrm{mex}(1, 1) = 0$

3 2
0 1 0
2

We have:

  • for $i = 0$: $\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \mathrm{mex}(0, 1) = 2$
  • for $i = 1$: $\mathrm{mex}(A_{i + 1}, A_{i + 2}) = \mathrm{mex}(1, 0) = 2$

7 3
0 0 1 2 0 1 0
2

2024春季入门组刷题营(八)

未参加
状态
已结束
规则
IOI
题目
8
开始于
2024-5-5 13:00
结束于
2024-5-5 15:00
持续时间
2 小时
主持人
参赛人数
11