C. [R16C]三元组2

    Type: Default 1000ms 512MiB

[R16C]三元组2

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

时空限制

1S/512M

题目描述

给定一个长度为 nn 的整数数组 AA,求有多少个三元组 (i,j,k)(i,j,k) 同时满足以下两个条件:

  • i<j<ki < j < k
  • min(Ai,Ak)AiAk\min(A_i,A_k)\leq |A_i-A_k|

格式

输入格式

第一行包含一个整数 nn,表示数组的长度。

第二行包含 nn 个整数 AiA_i

输出格式

输出一个整数,表示符合条件的三元组的数量。

样例

样例输入 #1

5
4 5 3 1 6

样例输出 #1

4

样例解释 #1

符合条件的三元组有 44 个:(1,2,4)(1,2,4)(1,3,4)(1,3,4)(2,3,4)(2,3,4)(3,4,5)(3,4,5)

数据规模

对于 40%40\% 的数据, n100n\leq 100

对于 100%100\% 的数据, 3n50003\leq n\leq 50001Ai1091\leq A_i\leq 10^9

代码源挑战赛 Round 16

Not Attended
Status
Done
Rule
DMY
Problem
6
Start at
2025-6-13 20:00
End at
2025-6-13 21:30
Duration
1.5 hour(s)
Host
Partic.
507