QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 2048 MB 總分: 100

#15923. Neighborhood Watch

统计

Jennifer 被提名为社区守望(neighborhood watch)队长,现在负责管理她所在街道的守望工作。

Jennifer 所在的街道上,房子只分布在道路的一侧。她有一份关于哪些房子将作为社区守望屋的计划,并想知道这个计划有多安全。从一栋房子到另一栋房子(不一定不同)的步行路径,如果路径上至少包含一栋社区守望屋,则被认为是安全的。一个计划的安全评级是街道上安全步行路径的数量。由于一条步行路径要么安全,要么不安全,因此在任一方向上移动时,它在安全评级中不会被重复计算。

图 1:样例输入。一个安全步行路径的例子是从房子 1 走到房子 5。

请告诉 Jennifer 她的计划的安全评级。

输入格式

第一行包含两个整数 $N$ ($1 \le N \le 200\,000$),表示街道上的房子数量,以及 $K$ ($0 \le K \le N$),表示 Jennifer 计划中的社区守望屋数量。房子的编号为 $1, \dots, N$。

接下来的 $K$ 行描述社区守望屋。这些行中的每一行都包含一个整数 $H$ ($1 \le H \le N$),表示社区守望屋的房子编号。房子编号按严格递增的顺序给出。

输出格式

输出 Jennifer 计划的安全评级。

样例

输入样例 1

5 2
1
4

输出样例 1

11

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.