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
如上是一段计算数组权值的伪代码,通过调用 f(1,m,s)f(1,m,s)f(1,m,s)
计算一个长度为 m 的数组 的权值,现在 Bingbong
有一个长度为 n 的数组 ,请你帮助他求出所有非空子数组的权值之和。