結果

問題 No.3257 +|+
ユーザー Iroha_3856
提出日時 2025-09-05 03:55:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,489 ms / 3,000 ms
コード長 515 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 82,984 KB
実行使用メモリ 252,608 KB
最終ジャッジ日時 2025-09-05 15:05:30
合計ジャッジ時間 38,724 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from bisect import bisect_left, bisect_right

N = int(input())
M = 200000
A = list(map(int, input().split()))

C = [[] for i in range(2*M+1)]

for i in range(N):
	for d in range(1, (A[i] + M) // (i+1) + 1):
		C[d].append(A[i] - (i+1) * d)

ans = 0
for d in range(1, (2 * M) // 3 + 1):
	C[d].sort()
	cnt0 = 0
	for c in C[d]:
		if c > 0:
			break
		elif c == 0:
			cnt0 += 1
		else:
			ans += bisect_right(C[d], -c) - bisect_left(C[d], -c)
	ans += cnt0 * (cnt0 - 1) // 2
print(ans)
0