CF1147A.Hide and Seek

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob are playing a game on a line with nn cells. There are nn cells labeled from 11 through nn. For each ii from 11 to n−1n-1, cells ii and i+1i+1 are adjacent.

Alice initially has a token on some cell on the line, and Bob tries to guess where it is.

Bob guesses a sequence of line cell numbers x1,x2,…,xkx_1, x_2, \ldots, x_k in order. In the ii-th question, Bob asks Alice if her token is currently on cell xix_i. That is, Alice can answer either "YES" or "NO" to each Bob's question.

At most one time in this process, before or after answering a question, Alice is allowed to move her token from her current cell to some adjacent cell. Alice acted in such a way that she was able to answer "NO" to all of Bob's questions.

Note that Alice can even move her token before answering the first question or after answering the last question. Alice can also choose to not move at all.

You are given nn and Bob's questions x1,…,xkx_1, \ldots, x_k. You would like to count the number of scenarios that let Alice answer "NO" to all of Bob's questions.

Let (a,b)(a,b) denote a scenario where Alice starts at cell aa and ends at cell bb. Two scenarios (ai,bi)(a_i, b_i) and (aj,bj)(a_j, b_j) are different if ai≠aja_i \neq a_j or bi≠bjb_i \neq b_j.

爱丽丝和鲍勃在一条包含 nn 个格子的直线上进行一个游戏。这 nn 个格子依次编号为 11 到 nn。对每个 ii(1≤i≤n−11 \le i \le n-1),格子 ii 与格子 i+1i+1 相邻。

初始时,爱丽丝将一个标记放在直线上的某个格子上,而鲍勃试图猜出该标记的位置。

鲍勃按顺序提出一系列格子编号 x1,x2,…,xkx_1, x_2, \ldots, x_k 作为猜测。在第 ii 次提问中,鲍勃询问爱丽丝:她的标记当前是否位于格子 xix_i 上?也就是说,爱丽丝对鲍勃的每个问题只能回答“是”(YES)或“否”(NO)。

在整个过程中,爱丽丝至多有一次机会——可在回答任一问题之前或之后——将她的标记从当前所在格子移动到一个相邻格子。爱丽丝采取了某种策略,使得她能够对鲍勃的所有问题均回答“否”。

注意:爱丽丝甚至可以在回答第一个问题之前、或在回答最后一个问题之后移动标记;她也可以选择完全不移动。

现给定 nn 和鲍勃的提问序列 x1,…,xkx_1, \ldots, x_k,你需要计算所有能使爱丽丝对鲍勃全部问题均回答“否”的情形总数。

用 (a,b)(a,b) 表示一种情形,其中爱丽丝起始位置为格子 aa,最终位置为格子 bb。若 (ai,bi)(a_i, b_i) 与 (aj,bj)(a_j, b_j) 满足 ai≠aja_i \neq a_j 或 bi≠bjb_i \neq b_j,则认为二者是不同的情形。

输入格式

The first line contains two integers nn and kk (1≤n,k≤1051 \leq n,k \leq 10^5) — the number of cells and the number of questions Bob asked.

The second line contains kk integers x1,x2,…,xkx_1, x_2, \ldots, x_k (1≤xi≤n1 \leq x_i \leq n) — Bob's questions.

第一行包含两个整数 nn 和 kk(1≤n,k≤1051 \leq n,k \leq 10^5)—— 分别表示单元格的数量和鲍勃提出的问题数量。

第二行包含 kk 个整数 x1,x2,…,xkx_1, x_2, \ldots, x_k(1≤xi≤n1 \leq x_i \leq n)—— 鲍勃提出的问题。

输出格式

Print a single integer, the number of scenarios that let Alice answer "NO" to all of Bob's questions.

输出一个整数,表示使得 Alice 对 Bob 的所有问题均回答“NO”的情形数量。

输入输出样例

  • 输入#1

    5 3
    5 1 4

    输出#1

    9
  • 输入#2

    4 8
    1 2 3 4 4 3 2 1

    输出#2

    0
  • 输入#3

    100000 1
    42

    输出#3

    299997

说明/提示

The notation (i,j)(i,j) denotes a scenario where Alice starts at cell ii and ends at cell jj.

In the first example, the valid scenarios are (1,2),(2,1),(2,2),(2,3),(3,2),(3,3),(3,4),(4,3),(4,5)(1, 2), (2, 1), (2, 2), (2, 3), (3, 2), (3, 3), (3, 4), (4, 3), (4, 5). For example, (3,4)(3,4) is valid since Alice can start at cell 33, stay there for the first three questions, then move to cell 44 after the last question.

(4,5)(4,5) is valid since Alice can start at cell 44, stay there for the first question, the move to cell 55 for the next two questions. Note that (4,5)(4,5) is only counted once, even though there are different questions that Alice can choose to do the move, but remember, we only count each pair of starting and ending positions once.

In the second example, Alice has no valid scenarios.

In the last example, all (i,j)(i,j) where ∣i−j∣≤1|i-j| \leq 1 except for (42,42)(42, 42) are valid scenarios.

符号 (i,j)(i,j) 表示爱丽丝从第 ii 个格子出发、最终到达第 jj 个格子的情形。

在第一个样例中,所有合法的情形为 (1,2),(2,1),(2,2),(2,3),(3,2),(3,3),(3,4),(4,3),(4,5)(1, 2), (2, 1), (2, 2), (2, 3), (3, 2), (3, 3), (3, 4), (4, 3), (4, 5)。例如,(3,4)(3,4) 是合法的,因为爱丽丝可以从第 33 个格子出发,在前三个问题期间一直停留在该格子,然后在最后一个问题之后移动到第 44 个格子。

(4,5)(4,5) 也是合法的,因为爱丽丝可以从第 44 个格子出发,在第一个问题期间停留于此,然后在接下来的两个问题期间移动并停留在第 55 个格子。注意,尽管爱丽丝可在不同问题时刻执行该移动,(4,5)(4,5) 仅被计数一次——因为我们只对每一对起始位置与结束位置计数一次。

在第二个样例中,爱丽丝没有任何合法的情形。

在最后一个样例中,所有满足 ∣i−j∣≤1|i-j| \leq 1 的 (i,j)(i,j) 均为合法情形,但 (42,42)(42, 42) 除外。

输入解题思路,AI测评打分。不知道怎么写?

首页