#T2342. 不同值之和(Distinct Values Sum)

不同值之和(Distinct Values Sum)

链接: https://cses.fi/problemset/task/3150

板块: Additional Problems I

时限: 1.00 s | 内存: 512 MB

题目描述

给定一个数组 x1,x2,,xnx_1,x_2,\dots,x_n。令 d(a,b)d(a,b) 表示子数组 xa,xa+1,,xbx_a,x_{a+1},\dots,x_b 中不同值的数量。

你的任务是计算 a=1nb=and(a,b)\sum_{a=1}^n \sum_{b=a}^n d(a,b),即所有子数组的 d(a,b)d(a,b) 之和。

输入

第一行包含一个整数 nn:数组的大小。

下一行包含 nn 个整数 x1,x2,,xnx_1,x_2,\dots,x_n:数组的内容。

输出

输出一个整数:要求的和。

数据范围

1n21051 \le n \le 2 \cdot 10^5 1xi1091 \le x_i \le 10^9

样例输入

5
1 2 3 1 1

样例输出

29