영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
시간 제한 1초 · 메모리 제한 512 MB
Problem
You are given an array x_1,x_2,…,x_n. Let d(a,b) denote the number of distinct values in the subarray x_a,x_{a+1},…,x_b.
Your task is to calculate the sum ∑_{a=1}^n ∑_{b=a}^n d(a,b), i.e., the sum of d(a,b) for all subarrays.
Input
The first line has an integer n: the array size.
The next line has n integers x_1,x_2,…,x_n: the array contents.
Output
Print one integer: the required sum.
Constraints
- 1 ≤ n ≤ 2 · 10^5
- 1 ≤ x_i ≤ 10^9
Example
Explanation: In this array, 6 subarrays have 1 distinct value, 4 subarrays have 2 distinct values and 5 subarrays have 3 distinct values. Thus, the sum is 6 · 1+4 · 2+5 · 3=29.
예제
예제 1
5 1 2 3 1 1
29