题目描述
You are given an array A of length N.
Determine the count of subarrays of A which contain their length as an element.
Formally, count the number of pairs (L, R) (1≤ L≤ R≤ N) such that: $(R-L+1) \in$ ${A_{L}, A_{L+1}, \ldots, A_{R}$}.
------ Input Format ------
- First line will contain T, number of test cases. Then the test cases follow.
- First line of each test case contains an integer N denoting the length of the array A.
- Second line of each test case contains $N space-separated integers A_{1}, A_{2}, \ldots, A_{N} -$ denoting the array A.
------ Output Format ------
For each test case, output the count of subarrays containing their lengths.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 2 \cdot 10^{5}$
$1 ≤ A_{i} ≤ N$
- Sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
1 2 1
5
2 3 1 3 5
10
10 7 4 4 2 9 2 1 9 3
----- Sample Output 1 ------
4
6
15
----- explanation 1 ------
Test Case $1$: There are $4$ subarrays $(i,j)$ containing their lengths. They are $(1,1), (1,2), (2,3),$ and $(3,3)$.
Test Case $2$: There are $6$ subarrays $(i,j)$ containing their lengths. They are $(1,2), (1,3), (1,5), (2, 4), (3,3),$ and $(3,5)$.
输入格式
见题面
输出格式
见题面