問題一覧 > 通常問題

No.2053 12345...

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 122
作問者 : PCTprobability / テスター : butsurizuki
お気に入りにしたユーザー ProblemId : 8359 / 自分の提出
問題文最終更新日: 2026-10-16 15:22:43
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
NPCA 合宿コンテスト (順位表) の他の問題:

Problem Statement

You are given a sequence of positive integers $A_1,A_2,\dots,A_N$ of length $N$.

Find the number of contiguous subarrays of $A$ of length at least $2$ that are arithmetic progressions with common difference $1$.

Constraints

  • $2 \le N \le 2 \times 10^5$
  • $1 \le A_i \le 10^9$
  • $A_{i+1} \neq A_i - 1 \ (1 \le i \le N-1)$
  • All input values are integers.

Input

$N$
$A_1$ $A_2$ $\dots$ $A_N$

Output

Output the answer.

Sample

Sample 1
Input
5
2 3 4 1 1
Output
3

The contiguous subarray $(2,3,4)$ consisting of the $1$-st through $3$-rd elements is an arithmetic progression with common difference $1$, so it satisfies the condition.

The contiguous subarray $(3,4,1)$ consisting of the $2$-nd through $4$-th elements is not an arithmetic progression, so it does not satisfy the condition.

The contiguous subarray $(4)$ consisting of the $3$-rd through $3$-rd elements does not have length at least $2$, so it does not satisfy the condition.

Sample 2
Input
10
1 2 3 4 5 6 7 8 9 10
Output
45

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