CF2226B.Everything Everywhere
入门
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
An array is called good if the difference between the maximum value and the minimum value in the array is equal to the greatest common divisor (GCD) of all the elements in the array. Note that an empty array is considered to be not good.
More formally, an array [a1,a2,…,am] is good if and only if $$ \max(a_1, a_2, \ldots, a_m) - \min(a_1, a_2, \ldots, a_m) = \gcd(a_1, a_2, \ldots, a_m).$$
You are given a permutation∗ p of length n. Determine the number of good subarrays† in the given permutation.
∗A permutation of length m is an array consisting of m distinct integers from 1 to m in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (m=3 but there is 4 in the array).
†An array b is a subarray of an array a if b can be obtained from a by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
如果一个数组中最大值与最小值的差等于该数组所有元素的最大公约数(GCD),则称该数组为“好”数组。注意:空数组不被视为好数组。
更形式化地,数组 [a1,a2,…,am] 是好数组,当且仅当
max(a1,a2,…,am)−min(a1,a2,…,am)=gcd(a1,a2,…,am).
给定一个长度为 n 的排列∗ p,请确定该排列中“好”子数组† 的个数。
∗ 长度为 m 的排列是指由 1 到 m 这 m 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4] 是一个排列,而 [1,2,2] 不是排列(数字 2 在数组中出现了两次),[1,3,4] 也不是排列(此时 m=3,但数组中却出现了 4)。
† 若数组 b 可通过从数组 a 的开头删除若干(可能为零或全部)元素、并从结尾删除若干(可能为零或全部)元素得到,则称 b 是 a 的一个子数组。特别地,一个数组是其自身的子数组。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each testcase contains a single integer n (2≤n≤2⋅105) — the length of the permutation p.
The second line of each testcase contains n integers p1,p2,…,pn (1≤pi≤n) — the permutation p. It is guaranteed that p is a permutation.
It is guaranteed that the sum of n over all the test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤2⋅105)—— 排列 p 的长度。
每个测试用例的第二行包含 n 个整数 p1,p2,…,pn(1≤pi≤n)—— 排列 p。保证 p 是一个排列。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each testcase, print a single integer — the number of good subarrays in the given permutation.
对于每个测试用例,输出一个整数——给定排列中“好”子数组的个数。
输入输出样例
输入#1
3 2 1 2 9 6 1 5 9 4 7 2 8 3 4 1 2 3 4
输出#1
1 0 3
说明/提示
For the first testcase, only one subarray is good, which is [1,2].
For the second testcase, it can be proven that no good subarrays exist in the given permutation.
对于第一个测试用例,只有一个好子数组,即 [1,2]。
对于第二个测试用例,可以证明在给定的排列中不存在好子数组。
输入解题思路,AI测评打分。不知道怎么写?