CF1730E.Maximums and Minimums
普及/提高-
通过率:0%
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.
输入格式
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 .
输出格式
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.