CF1730E.Maximums and Minimums
省选/NOI-
通过率:0%
时间限制:5.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an of positive integers.
Find the number of pairs of indices (l,r), where 1≤l≤r≤n, that pass the check. The check is performed in the following manner:
- The minimum and maximum numbers are found among al,al+1,…,ar.
- The check is passed if the maximum number is divisible by the minimum number.
给你一个正整数数组 a1,a2,…,an。
求满足条件的索引对 (l,r) 的数量,其中 1≤l≤r≤n。判断条件如下:
- 在子数组 al,al+1,…,ar 中找出最小值和最大值;
- 若最大值能被最小值整除,则该索引对通过判断。
输入格式
The first line contains a single integer t (1≤t≤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 n (1≤n≤5⋅105) — the size of the array.
The second line contains n integers a1,a2,…,an (1≤ai≤106).
It is guaranteed that the sum of n over all test cases does not exceed 5⋅105.
第一行包含一个整数 t(1≤t≤10)—— 测试用例的数量。随后是各测试用例。
每个测试用例由两行组成。
第一行包含一个整数 n(1≤n≤5⋅105)—— 数组的大小。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤106)。
保证所有测试用例的 n 之和不超过 5⋅105。
输出格式
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∣y denotes that y is divisible by x.
In the first test case, there is one pair (1,1), the maximum for this pair is 1, the minimum is also 1, 1∣1, so the check is passed, and the answer is 1.
In the second test case, there are 3 segments:
- (1,1): the maximum is 2, the minimum is 2, 2∣2, so the check is passed.
- (1,2): the maximum is 4, the minimum is 2, 2∣4, so the check is passed.
- (2,2): the maximum is 4, the minimum is 4, 4∣4, so the check is passed.
In the third test case, there are 3 segments:
- (1,1): the maximum is 2, the minimum is 2, 2∣2, so the check is passed.
- (1,2): the maximum is 3, the minimum is 2, 3 isn't divisible by 2, so the check is failed.
- (2,2): the maximum is 3, the minimum is 3, 3∣3, so the check is passed.
其中 x∣y 表示 y 能被 x 整除。
在第一个测试用例中,存在一对 (1,1),该对的最大值为 1,最小值也为 1,且 1∣1,因此检查通过,答案为 1。
在第二个测试用例中,共有 3 个区间:
- (1,1):最大值为 2,最小值为 2,且 2∣2,因此检查通过。
- (1,2):最大值为 4,最小值为 2,且 2∣4,因此检查通过。
- (2,2):最大值为 4,最小值为 4,且 4∣4,因此检查通过。
在第三个测试用例中,共有 3 个区间:
- (1,1):最大值为 2,最小值为 2,且 2∣2,因此检查通过。
- (1,2):最大值为 3,最小值为 2,但 3 不能被 2 整除,因此检查失败。
- (2,2):最大值为 3,最小值为 3,且 3∣3,因此检查通过。
输入解题思路,AI测评打分。不知道怎么写?