[Solution] Good Subarrays (Easy Version) solution codeforces

Good Subarrays (Easy Version) solution codeforces – An array 𝑏b of length 𝑚m is good if for all 𝑖i the 𝑖i-th element is greater than or equal to 𝑖i. In other words, 𝑏b is good if and only if 𝑏𝑖𝑖bi≥i for all 𝑖i (1𝑖𝑚1≤i≤m).

Table of Contents

[Solution] Good Subarrays (Easy Version) solution codeforces

You are given an array 𝑎a consisting of 𝑛n positive integers. Find the number of pairs of indices (𝑙,𝑟)(l,r), where 1𝑙𝑟𝑛1≤l≤r≤n, such that the array [𝑎𝑙,𝑎𝑙+1,,𝑎𝑟][al,al+1,…,ar] is good.

Input

Each test contains multiple test cases. The first line contains the number of test cases 𝑡t (1𝑡21051≤t≤2⋅105). Description of the test cases follows.

The first line of each test case contains an integer 𝑛n (1𝑛21051≤n≤2⋅105), the length of the array 𝑎a.

The second line of each test case contains 𝑛n space-separated integers 𝑎1,𝑎2,,𝑎𝑛a1,a2,…,an (1𝑎𝑖𝑛1≤ai≤n), representing the array 𝑎a.

It is guaranteed that the sum of 𝑛n over all test cases does not exceed 21052⋅105.

Output

For each test case, print the number of suitable pairs of indices.

[Solution] Good Subarrays (Easy Version) solution codeforces

input

Copy
3
3
1 2 3
3
1 1 1
4
2 1 4 3
output

Copy
6
3
7

[Solution] Good Subarrays (Easy Version) solution codeforces

In the first test case, all subarrays of 𝑎a are good, so all pairs are suitable.

In the second test case, the pairs (1,1)(1,1)(2,2)(2,2), and (3,3)(3,3) are suitable. For example, when (𝑙,𝑟)=(1,2)(l,r)=(1,2), the array 𝑏=[1,1]b=[1,1] is not good because 𝑏2<2b2<2.

For Solution

“Click Here”

Leave a Comment