Distinct Values Sum
You are given an array x_1,x_2,\dots,x_n. Let d(a,b) denote the number of distinct values in the subarray x_a,x_{a+1},\dots,x_b. Your task is to calculate the sum \sum_{a=1}^n \sum_{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,\dots,x_n: the array contents. Output Print one integer: the r
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start