## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## [Solution] Subarrays with length CodeChef Solution | CodeChef Problem Solution 2022

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 $\left(L,R\right)$ $\left(1\le L\le R\le N\right)$ such that: $\left(R-L+1\right)\in \left\{{A}_{L},{A}_{L+1},\dots ,{A}_{R}\right\}$.

### 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},\dots ,{A}_{N}$ - denoting the array $A$.

### Output Format

For each test case, output the count of subarrays containing their lengths.

### Constraints

• $1\le T\le 1000$
• $1\le N\le 2\cdot {10}^{5}$
• $1\le {A}_{i}\le N$
• Sum of $N$ over all test cases does not exceed $5\cdot {10}^{5}$.