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
每个测试文件均包含多组测试数据。第一行输入一个整数
,代表数据组数,每组测试数据描述如下:
第一行输入一个整数
,表示数组长度。
第二行输入
个整数
,表示数组中的元素。
除此之外,保证单个测试文件的
之和不超过
。
对于每一组测试数据,新起一行输出一个整数,表示所有子数组的权值之和。