問題一覧 > 通常問題

No.3091 The Little Match Boy

レベル : / AI推定難易度 : 1100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 78
作問者 : RiRinbaru / テスター : autumn09 downer hamo21 ygussany
お気に入りにしたユーザー ProblemId : 11593 / 自分の提出
問題文最終更新日: 2025-04-06 13:26:39
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
QUPC2024 (順位表) の他の問題:

Problem Statement

RiRinbaru was happily making an Amidakuji (ladder lottery) using the matchsticks he had at home.

First, RiRinbaru drew $N$ sufficiently long vertical lines in parallel at intervals of length $1$. He builds the Amidakuji by placing matchsticks so that they bridge these lines. He places $M$ matchsticks of length $1$, each connecting $2$ adjacent vertical lines. The $i$-th matchstick from the top was placed so that its left vertical line is the $S_i$-th from the left.
Two results of an Amidakuji are considered different if the endpoint reached from some starting point differs.

RiRinbaru was having fun, but his mother told him she wanted a matchstick, so he must choose $1$ of the matchsticks he was using and remove it from the Amidakuji.
How many different results are possible for the Amidakuji obtained by removing $1$ horizontal stick from it?

Input

$N\ M$
$S_1\ S_2\ ...\ S_M$
  • $2\leq N\leq 10^5$
  • $1\leq M\leq 10^5$
  • $1\leq S_i< N$
  • All inputs are integers.

Output

Output the number of possible kinds of final results.
Print a newline at the end.

Sample

Sample 1
Input
3 4
1 2 1 1
Output
3

When the matchsticks are removed in order starting from the one with the smallest height from the top, the final results are as follows.

  • $(1,\ 3,\ 2)$
  • $(2,\ 1,\ 3)$
  • $(3,\ 2,\ 1)$
  • $(3,\ 2,\ 1)$
Therefore, the number of kinds, 3, is the answer.

Sample 2
Input
4 10
1 3 1 2 3 2 3 2 1 3
Output
4

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。