No.3456 Common Difference is D
レベル :
/ AI推定難易度 : 850
/ 実行時間制限 : 1ケース 2.000秒 / メモリ制限
: 512 MB / 標準ジャッジ問題
タグ : / 解いたユーザー数 82
作問者 :
くらげ
/ テスター :
dyktr_06
おのせ
hikikomori
tyawanmusi
タグ : / 解いたユーザー数 82
作問者 :
くらげ
/ テスター :
hikikomori
問題文最終更新日: 2026-02-27 23:41:50
English (AI translation)
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
MMA Contest 021
(順位表)
の他の問題:
Problem Statement
You are given an integer sequence $A = ( A_1, A_2, \dots, A_N )$ of length $N$ and a positive integer $D$. Find the number of subsequences of $A$ that have length $3$ and form an arithmetic progression with common difference $D$.
More precisely, find the number of tuples $(i, j, k)$ satisfying the following conditions.
- $1 \le i < j < k \le N$
- $A_i < A_j < A_k$
- $A_j - A_i = A_k - A_j = D$
Constraints
- $3 \le N \le 10^5$
- $1 \le D \le 5 \times 10^8$
- $0 \le A_i \le 10^9$ $(1 \le i \le N)$
- All input values are integers
Input
$N$ $D$ $A_1$ $A_2$ $\dots$ $A_N$
Output
Print the number of tuples $(i, j, k)$ satisfying the conditions on $1$ line.
Sample
Sample 1
Input
7 2 0 2 5 1 4 3 6
Output
2
The subsequences of $A$ satisfying the conditions are the following $2$: $(A_i, A_j, A_k) = (0, 2, 4), (2, 4, 6)$.
Sample
Sample 2
Input
6 1 1 1 2 2 3 3
Output
8
Note that even if $(A_i, A_j, A_k)$ are identical as sequences, they are counted separately if the choices of $(i, j, k)$ differ.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。