CF1730E.Maximums and Minimums

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_n of positive integers.

Find the number of pairs of indices (l,r)(l, r), where 1≤l≤r≤n1 \le l \le r \le n, that pass the check. The check is performed in the following manner:

  1. The minimum and maximum numbers are found among al,al+1,…,ara_l, a_{l+1}, \ldots, a_r.
  2. The check is passed if the maximum number is divisible by the minimum number.

给你一个正整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n。

求满足条件的索引对 (l,r)(l, r) 的数量,其中 1≤l≤r≤n1 \le l \le r \le n。判断条件如下:

  1. 在子数组 al,al+1,…,ara_l, a_{l+1}, \ldots, a_r 中找出最小值和最大值;
  2. 若最大值能被最小值整除,则该索引对通过判断。

输入格式

The first line contains a single integer tt (1≤t≤101 \le t \le 10) — the number of test cases. Then the test cases follow.

Each test case consists of two lines.

The first line contains a single integer nn (1≤n≤5⋅1051 \le n \le 5 \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≤1061 \le a_i \le 10^6).

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

第一行包含一个整数 tt(1≤t≤101 \le t \le 10)—— 测试用例的数量。随后是各测试用例。

每个测试用例由两行组成。

第一行包含一个整数 nn(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5)—— 数组的大小。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061 \le a_i \le 10^6)。

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

输出格式

For each test case, print a single integer — the number of pairs of indices that pass the check.

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

输入输出样例

  • 输入#1

    6
    1
    1
    2
    2 4
    2
    2 3
    4
    2 4 7 14
    7
    16 5 18 7 7 12 14
    6
    16 14 2 6 16 2

    输出#1

    1
    3
    2
    7
    10
    19

说明/提示

Below x∣yx \mid y denotes that yy is divisible by xx.

In the first test case, there is one pair (1,1)(1, 1), the maximum for this pair is 11, the minimum is also 11, 1∣11 \mid 1, so the check is passed, and the answer is 11.

In the second test case, there are 33 segments:

  • (1,1)(1, 1): the maximum is 22, the minimum is 22, 2∣22 \mid 2, so the check is passed.
  • (1,2)(1, 2): the maximum is 44, the minimum is 22, 2∣42 \mid 4, so the check is passed.
  • (2,2)(2, 2): the maximum is 44, the minimum is 44, 4∣44 \mid 4, so the check is passed.

In the third test case, there are 33 segments:

  • (1,1)(1, 1): the maximum is 22, the minimum is 22, 2∣22 \mid 2, so the check is passed.
  • (1,2)(1, 2): the maximum is 33, the minimum is 22, 33 isn't divisible by 22, so the check is failed.
  • (2,2)(2, 2): the maximum is 33, the minimum is 33, 3∣33 \mid 3, so the check is passed.

其中 x∣yx \mid y 表示 yy 能被 xx 整除。

在第一个测试用例中,存在一对 (1,1)(1, 1),该对的最大值为 11,最小值也为 11,且 1∣11 \mid 1,因此检查通过,答案为 11。

在第二个测试用例中,共有 33 个区间:

  • (1,1)(1, 1):最大值为 22,最小值为 22,且 2∣22 \mid 2,因此检查通过。
  • (1,2)(1, 2):最大值为 44,最小值为 22,且 2∣42 \mid 4,因此检查通过。
  • (2,2)(2, 2):最大值为 44,最小值为 44,且 4∣44 \mid 4,因此检查通过。

在第三个测试用例中,共有 33 个区间:

  • (1,1)(1, 1):最大值为 22,最小值为 22,且 2∣22 \mid 2,因此检查通过。
  • (1,2)(1, 2):最大值为 33,最小值为 22,但 33 不能被 22 整除,因此检查失败。
  • (2,2)(2, 2):最大值为 33,最小值为 33,且 3∣33 \mid 3,因此检查通过。

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

首页