CF1147A.Hide and Seek
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n . For each i from 1 to n−1 , cells i and i+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,…,xk in order. In the i -th question, Bob asks Alice if her token is currently on cell xi . 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 n and Bob's questions x1,…,xk . You would like to count the number of scenarios that let Alice answer "NO" to all of Bob's questions.
Let (a,b) denote a scenario where Alice starts at cell a and ends at cell b . Two scenarios (ai,bi) and (aj,bj) are different if ai=aj or bi=bj .
输入格式
The first line contains two integers n and k ( 1≤n,k≤105 ) — the number of cells and the number of questions Bob asked.
The second line contains k integers x1,x2,…,xk ( 1≤xi≤n ) — Bob's questions.
输出格式
Print a single integer, the number of scenarios that let Alice answer "NO" to all of Bob's questions.
输入输出样例
输入#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) denotes a scenario where Alice starts at cell i and ends at cell j .
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) . For example, (3,4) is valid since Alice can start at cell 3 , stay there for the first three questions, then move to cell 4 after the last question.
(4,5) is valid since Alice can start at cell 4 , stay there for the first question, the move to cell 5 for the next two questions. Note that (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) where ∣i−j∣≤1 except for (42,42) are valid scenarios.