CF1736C1.Good Subarrays (Easy Version)

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easy version of this problem. In this version, we do not have queries. Note that we have multiple test cases in this version. You can make hacks only if both versions of the problem are solved.

An array bb of length mm is good if for all ii the ii-th element is greater than or equal to ii. In other words, bb is good if and only if bi≥ib_i \geq i for all ii (1≤i≤m1 \leq i \leq m).

You are given an array aa consisting of nn positive integers. Find the number of pairs of indices (l,r)(l, r), where 1≤l≤r≤n1 \le l \le r \le n, such that the array [al,al+1,…,ar][a_l, a_{l+1}, \ldots, a_r] is good.

本题是该问题的简单版本。在此版本中,我们不需要处理查询。请注意,此版本包含多个测试用例。仅当两个版本的问题均被解决时,才允许进行 hack。

长度为 mm 的数组 bb 被称为好数组,当且仅当对所有 ii,第 ii 个元素不小于 ii。换言之,bb 是好数组当且仅当对所有 ii(1≤i≤m1 \leq i \leq m)满足 bi≥ib_i \geq i。

给定一个由 nn 个正整数组成的数组 aa。请找出满足条件的下标对 (l,r)(l, r) 的数量,其中 1≤l≤r≤n1 \le l \le r \le n,使得子数组 [al,al+1,…,ar][a_l, a_{l+1}, \ldots, a_r] 是好数组。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤2⋅1051 \leq t \leq 2 \cdot 10^5). Description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5), the length of the array aa.

The second line of each test case contains nn space-separated integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤n1 \leq a_i \leq n), representing the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤2⋅1051 \leq t \leq 2 \cdot 10^5)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5),表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个以空格分隔的整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤n1 \leq a_i \leq n),表示数组 aa。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

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

对于每个测试用例,输出满足条件的索引对的数量。

输入输出样例

  • 输入#1

    3
    3
    1 2 3
    3
    1 1 1
    4
    2 1 4 3

    输出#1

    6
    3
    7

说明/提示

In the first test case, all subarrays of aa 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 (l,r)=(1,2)(l, r) = (1, 2), the array b=[1,1]b=[1,1] is not good because b2<2b_2 \lt 2.

在第一个测试用例中,数组 aa 的所有子数组都是“好”的,因此所有数对都满足条件。

在第二个测试用例中,满足条件的数对为 (1,1)(1, 1)、(2,2)(2, 2) 和 (3,3)(3, 3)。例如,当 (l,r)=(1,2)(l, r) = (1, 2) 时,数组 b=[1,1]b=[1,1] 不是“好”的,因为 b2<2b_2 \lt 2。

输入解题思路,AI测评打分。不知道怎么写?

首页