#P13760. Clock Paradox

    ID: 14402 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学O2优化前缀和双指针 two-pointer

Clock Paradox

Background

(From a Phigros illustration, please contact for removal.)

Problem Description

Given a sequence aa, consider intervals [l,r][l,r] such that every number from ala_l to ara_r appears exactly once within this interval (i.e., all elements in the subarray are pairwise distinct). Suppose there are tt intervals that satisfy this requirement, numbered from [l1,r1][l_1,r_1] to [lt,rt][l_t,r_t].

Compute:

i=1tj=liriaj\sum_{i=1}^t\sum_{j=l_i}^{r_i}a_j

Output the answer modulo 109+710^9+7.

Input Format

The first line contains a positive integer nn, the length of the sequence.

The second line contains nn non-negative integers, representing the sequence aa.

Output Format

Output one non-negative integer, the value of the answer modulo 109+710^9+7.

6
1 2 3 3 2 1
40
13
1 1 4 5 1 4 1 9 1 9 8 1 0
239
10 
5 4 3 2 5 6 1 3 1 4
315

Hint

Constraints

Test Point ID nn aia_i Special Property
11 n2×105n\le2×10^5 0ai1090\le a_i\le10^9 A
22 B
3,43,4 n2×105n\le 2×10^5 0ai10\le a_i\le1
5,65,6 n500n\le500 0ai1090\le a_i\le10^9
7107\sim10 n5×103n\le 5×10^3 0ain0\le a_i\le n
112011\sim20 n2×105n\le2×10^5 0ai1090\le a_i\le10^9

Special Property A: all aia_i are equal.

Special Property B: all aia_i are pairwise distinct.

For 100%100\% of the testdata, 1n2×1051\le n\le2×10^5 and 0ai1090\le a_i\le 10^9.

Translated by ChatGPT 5