| Bitshift2026-IITM,ProgClub |
|---|
| Finished |
You are given an integer array $$$a$$$ of length $$$n$$$, where each element is an integer between $$$1$$$ and $$$10^9$$$.
For a value $$$x$$$, let $$$\text{freq}(x)$$$ denote the number of times $$$x$$$ appears in the entire array $$$a$$$.
A contiguous subarray $$$a[l \ldots r]$$$ is called complete if the following condition holds:
In other words, if a value appears in the subarray, then all of its occurrences in the whole array must be contained within that subarray.
You are given multiple test cases. For each test case, determine the total number of complete subarrays of $$$a$$$.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, print a single integer — the number of complete subarrays of $$$a$$$.
553 2 3 1 122 297 2 5 2 9 9 3 3 5105 10 6 1 9 2 7 2 4 397 1 6 5 1 2 9 6 3
4163710
In the first test case, subarrays $$$[2]$$$,$$$[1,1]$$$,$$$[3,2,3]$$$ and $$$[3,2,3,1,1]$$$ are complete while $$$[2,3]$$$ is not as it does not contain all occurrences of $$$3$$$.Thus,there are $$$4$$$ complete subarrays.
In the second test case, there is only one complete subarray, $$$[2,2]$$$.
| Name |
|---|


