CF1236E.Alice and the Unfair Game
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice is playing a game with her good friend, Marisa.
There are n boxes arranged in a line, numbered with integers from 1 to n from left to right. Marisa will hide a doll in one of the boxes. Then Alice will have m chances to guess where the doll is. If Alice will correctly guess the number of box, where doll is now, she will win the game, otherwise, her friend will win the game.
In order to win, Marisa will use some unfair tricks. After each time Alice guesses a box, she can move the doll to the neighboring box or just keep it at its place. Boxes i and i+1 are neighboring for all 1≤i≤n−1. She can also use this trick once before the game starts.
So, the game happens in this order: the game starts, Marisa makes the trick, Alice makes the first guess, Marisa makes the trick, Alice makes the second guess, Marisa makes the trick, …, Alice makes m-th guess, Marisa makes the trick, the game ends.
Alice has come up with a sequence a1,a2,…,am. In the i-th guess, she will ask if the doll is in the box ai. She wants to know the number of scenarios (x,y) (for all 1≤x,y≤n), such that Marisa can win the game if she will put the doll at the x-th box at the beginning and at the end of the game, the doll will be at the y-th box. Help her and calculate this number.
爱丽丝正在和她的好朋友玛莉莎玩一个游戏。
有 n 个盒子排成一行,从左到右依次编号为 1 到 n。玛莉莎会将一个洋娃娃藏在其中一个盒子里。随后,爱丽丝有 m 次机会来猜测洋娃娃所在的位置。如果爱丽丝能准确猜中洋娃娃当前所在的盒子编号,则她获胜;否则,她的朋友玛莉莎获胜。
为了确保获胜,玛莉莎会使用一些不公平的手段。每次爱丽丝猜测完一个盒子后,玛莉莎都可以将洋娃娃移动到相邻的盒子中,或者保持其位置不变。对所有满足 1≤i≤n−1 的 i,盒子 i 和 i+1 被视为相邻。此外,玛莉莎还可以在游戏开始前额外使用一次该手段。
因此,整个游戏按如下顺序进行:游戏开始 → 玛莉莎执行一次移动(可选)→ 爱丽丝进行第一次猜测 → 玛莉莎执行一次移动 → 爱丽丝进行第二次猜测 → 玛莉莎执行一次移动 → … → 爱丽丝进行第 m 次猜测 → 玛莉莎执行一次移动 → 游戏结束。
爱丽丝已设计出一个序列 a1,a2,…,am。在第 i 次猜测中,她将询问洋娃娃是否位于盒子 ai 中。她希望知道满足如下条件的场景 (x,y)(其中 1≤x,y≤n)的总数:若玛莉莎在游戏开始时将洋娃娃放在第 x 个盒子中,并且在游戏结束时洋娃娃恰好位于第 y 个盒子中,则玛莉莎能够获胜。请帮助她计算该数目。
输入格式
The first line contains two integers n and m, separated by space (1≤n,m≤105) — the number of boxes and the number of guesses, which Alice will make.
The next line contains m integers a1,a2,…,am, separated by spaces (1≤ai≤n), the number ai means the number of the box which Alice will guess in the i-th guess.
第一行包含两个整数 n 和 m,以空格分隔(1≤n,m≤105)——分别表示盒子的数量和爱丽丝将进行的猜测次数。
下一行包含 m 个整数 a1,a2,…,am,以空格分隔(1≤ai≤n),其中 ai 表示爱丽丝在第 i 次猜测中所猜的盒子编号。
输出格式
Print the number of scenarios in a single line, or the number of pairs of boxes (x,y) (1≤x,y≤n), such that if Marisa will put the doll into the box with number x, she can make tricks in such way, that at the end of the game the doll will be in the box with number y and she will win the game.
在一行中输出情景的数量,即满足以下条件的盒子对 (x,y)(其中 1≤x,y≤n)的个数:若魔理沙将玩偶放入编号为 x 的盒子中,则她能以某种方式施展戏法,使得游戏结束时玩偶位于编号为 y 的盒子中,且她赢得游戏。
输入输出样例
输入#1
3 3 2 2 2
输出#1
7
输入#2
5 2 3 1
输出#2
21
说明/提示
In the first example, the possible scenarios are (1,1), (1,2), (2,1), (2,2), (2,3), (3,2), (3,3).
Let's take (2,2) as an example. The boxes, in which the doll will be during the game can be 2→3→3→3→2
在第一个例子中,可能的情形有 (1,1)、(1,2)、(2,1)、(2,2)、(2,3)、(3,2)、(3,3)。
以 (2,2) 为例。玩偶在游戏过程中所处的盒子序列可以是 2→3→3→3→2。
输入解题思路,AI测评打分。不知道怎么写?