CF2227G.Drowning

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Yousef has an array aa consisting of nn positive integers.

He defines a reduction operation on any array cc of length ∣c∣≥3|c| \ge 3:

  • Choose an index ii (1<i<∣c∣1 \lt i \lt |c|) such that ci−1+ci+1>cic_{i-1} + c_{i+1} \gt c_i.
  • Replace the triplet ci−1,ci,ci+1{c_{i-1}, c_i, c_{i+1}} with a single integer x=ci−1−ci+ci+1x = c_{i-1} - c_i + c_{i+1}.

The new integer xx occupies the position previously held by the triplet, and the length of the array decreases by 22.

An array is considered good if it can be reduced to a single element by performing the operation above zero or more times. Note that an array of length 11 is always good.

Yousef wants you to count the number of pairs (l,r)(l, r) (1≤l≤r≤n1 \le l \le r \le n) such that the subarray a[l,r]a[l, r] is good.

优素福有一个由 nn 个正整数组成的数组 aa。

他对任意长度为 ∣c∣≥3|c| \ge 3 的数组 cc 定义了一种约简操作:

  • 选择一个下标 ii(满足 1<i<∣c∣1 \lt i \lt |c|),使得 ci−1+ci+1>cic_{i-1} + c_{i+1} \gt c_i;
  • 将三元组 {ci−1,ci,ci+1}\{c_{i-1}, c_i, c_{i+1}\} 替换为单个整数 x=ci−1−ci+ci+1x = c_{i-1} - c_i + c_{i+1}。

新整数 xx 占据原三元组所在的位置,数组长度因此减少 22。

若一个数组能通过零次或多次执行上述操作被约简为仅含一个元素,则称该数组是好的。注意:长度为 11 的数组总是好的。

优素福希望你统计满足条件的下标对 (l,r)(l, r)(其中 1≤l≤r≤n1 \le l \le r \le n)的个数,使得子数组 a[l,r]a[l, r] 是好的。

输入格式

The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of each test case follows.

The first line of each test case contains an integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the size of the array.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the elements of the array.

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

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。接下来是每个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示数组的大小。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 表示数组的元素。

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

输出格式

For each test case, output a single integer — the number of good subarrays.

对于每个测试用例,输出一个整数——即“好”子数组的个数。

输入输出样例

  • 输入#1

    4
    3
    10 20 10
    5
    1 1 1 1 1
    4
    5 1 5 1
    1
    100

    输出#1

    3
    9
    5
    1

说明/提示

In the first example, a=[10,20,10]a = [10, 20, 10]. Subarrays [10][10], [20][20], and [10][10] are all good (33 total). The subarray [10,20,10][10, 20, 10] is not good. To reduce it, we must pick i=2i=2. The condition a1+a3>a2a_1 + a_3 \gt a_2 becomes 10+10>2010 + 10 \gt 20, which is 20>2020 \gt 20 (false).

In the second example, a=[1,1,1,1,1]a = [1, 1, 1, 1, 1]:

  • All 55 subarrays of length 11 are good.
  • All 44 subarrays of length 22 are not good.
  • All 33 subarrays of length 33 (which are [1,1,1][1, 1, 1]) are good because 1+1>11 + 1 \gt 1.
  • All 22 subarrays of length 44 are not good.
  • The subarray of length 55 is good: [1,1,1,1,1]→i=2[1,1,1]→i=2[1][1, 1, 1, 1, 1] \xrightarrow{i=2} [1, 1, 1] \xrightarrow{i=2} [1].
  • Total good subarrays =5+3+1=9= 5 + 3 + 1 = 9.

在第一个例子中,a=[10,20,10]a = [10, 20, 10]。子数组 [10][10]、[20][20] 和 [10][10] 均为好子数组(共 33 个)。子数组 [10,20,10][10, 20, 10] 不是好子数组。要将其约简,我们必须选取 i=2i=2。条件 a1+a3>a2a_1 + a_3 \gt a_2 变为 10+10>2010 + 10 \gt 20,即 20>2020 \gt 20(不成立)。

在第二个例子中,a=[1,1,1,1,1]a = [1, 1, 1, 1, 1]:

  • 所有 55 个长度为 11 的子数组均为好子数组。
  • 所有 44 个长度为 22 的子数组均不是好子数组。
  • 所有 33 个长度为 33 的子数组(即 [1,1,1][1, 1, 1])均为好子数组,因为 1+1>11 + 1 \gt 1。
  • 所有 22 个长度为 44 的子数组均不是好子数组。
  • 长度为 55 的子数组是好子数组:[1,1,1,1,1]→i=2[1,1,1]→i=2[1][1, 1, 1, 1, 1] \xrightarrow{i=2} [1, 1, 1] \xrightarrow{i=2} [1]。
  • 好子数组总数 =5+3+1=9= 5 + 3 + 1 = 9。

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

首页