Unique Subarrays
Practice
3.9 (126 votes)
Data structures
Implementation
Medium
One Dimensional
Sets
Problem
16% Success 21205 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

A contiguous subarray is defined as unique if all the integers contained within it occur exactly once. There is a unique weight associated with each of the subarray. Unique weight for any subarray equals it's length if it's unique, 0 otherwise. Your task is to calculate the sum of unique weights of all the contiguous subarrays contained within a given array.

Input
First line of the input contains an integer T, denoting the number of testcases.
\(2*T\) lines follow, where first line of each testcase contains an integer N denoting the number of integers in the given array. Last line of each testcase then contains N single space separated integers

Output
Print the summation of unique weights of all the subarrays for each testcase in a separate line.

Constraints

  • \(1 ≤ T, N ≤ 10^{5}\)
  • \(0 ≤ A_i ≤ 10^{9}\)
  • Summation of N for all T does not exceed \(10^{5}\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
40 votes
Tags:
1-D ArrayArraysData StructuresEasyOne-dimensionalOpenapproved
Points:20
161 votes
Tags:
Ad-Hoc
Points:10
20 votes
Tags:
MathematicsApprovedVery-Easy