#P4755. Beautiful Pair

    ID: 3675 远端评测题 1500ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化枚举,暴力分治主席树洛谷月赛

Beautiful Pair

Description

Xiao D has a sequence {a}\{a\}. For a pair (i,j)(i, j) (iji \le j), if the product of aia_i and aja_j is not greater than the maximum value among ai,ai+1,,aja_i, a_{i+1}, \ldots, a_j, then Xiao D considers this pair to be beautiful. Please find the number of beautiful pairs.

Input Format

The first line contains an integer nn, representing the number of elements.
The second line contains nn integers a1,a2,a3,,ana_1, a_2, a_3, \ldots, a_n, representing the given sequence.

Output Format

Output one integer, the number of beautiful pairs.

4
1 3 9 3

5

5
1 1 2 1 1

14

Hint

[Sample Explanation #1]

The five valid pairs are (1,1),(1,2),(1,3),(1,4),(2,4)(1,1), (1,2), (1,3), (1,4), (2,4).

[Sample Explanation #2]

Only the pair (3,3)(3,3) is invalid.

[Constraints]

For 100%100\% of the testdata, 1n1051 \le n \le 10^5, and 1ai1091 \le a_i \le 10^9.

Translated by ChatGPT 5