权值计算
题号:NC302632
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述

Algorithm 1 函数 f 用于计算数组 s 的权值
 1: function f(l, r, s)
 2:     distinct ← ∅
 3:     total ← 0
 4:     current_count ← 0
 5:     for i ← l to r do
 6:         if s[i] ∉ distinct then
 7:             current_count ← current_count + 1
 8:             distinct ← distinct ∪ {s[i]}
 9:         end if
10:         total ← total + current_count
11:     end for
12:     return total
13: end function
\hspace{15pt}如上是一段计算数组权值的伪代码,通过调用 f(1,m,s) 计算一个长度为 m 的数组 s_1,s_2,\dots,s_m 的权值,现在 Bingbong 有一个长度为 n 的数组 a_1,a_2,\dots,a_n,请你帮助他求出所有非空子数组的权值之和。

【名词解释】
\hspace{15pt}子数组:从原数组中,连续的选择一段元素(可以全选、可以不选)得到的新数组。

输入描述:

\hspace{15pt}每个测试文件均包含多组测试数据。第一行输入一个整数 T\left(1\leq T\leq 10^4\right),代表数据组数,每组测试数据描述如下:

\hspace{15pt}第一行输入一个整数 n\left(1\leq n\leq 10^5\right),表示数组长度。
\hspace{15pt}第二行输入 n 个整数 a_1,a_2,\dots,a_n\left(1\leq a_i\leq 10^9\right),表示数组中的元素。

\hspace{15pt}除此之外,保证单个测试文件的 n 之和不超过 10^5

输出描述:

\hspace{15pt}对于每一组测试数据,新起一行输出一个整数,表示所有子数组的权值之和。
示例1

输入

复制
2
3
1 3 1
6
1 1 4 5 1 4

输出

复制
14
102