CF2276C.Subarrays

普及-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Monocarp has an array aa consisting of nn positive integers. He also has a favorite integer kk (k<nk \lt n).

A sequence of consecutive elements of the array with indices from ll to rr (1≤l≤r≤n1 \le l \le r \le n) is called a subarray. Monocarp calls a subarray kk-balanced if the following conditions hold:

  • the sum of all elements in the subarray from ll to rr inclusive is divisible by kk;
  • the length of this subarray is strictly greater than kk (that is, r−l+1>kr - l + 1 \gt k).

Help Monocarp determine the total number of kk-balanced subarrays in the array aa.

Monocarp 有一个由 nn 个正整数组成的数组 aa。他还拥有一个最喜欢的整数 kk(满足 k<nk \lt n)。

数组中从索引 ll 到 rr(1≤l≤r≤n1 \le l \le r \le n)的连续元素序列称为一个子数组。Monocarp 将满足以下条件的子数组称为 kk-平衡子数组:

  • 子数组 a[l..r]a[l..r] 中所有元素之和能被 kk 整除;
  • 该子数组的长度严格大于 kk(即 r−l+1>kr - l + 1 \gt k)。

请帮助 Monocarp 计算数组 aa 中 kk-平衡子数组的总数。

输入格式

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

The descriptions of the test cases follow.

The first line of each test case contains two integers nn and kk (1≤k<n≤2⋅1051 \le k \lt n \le 2 \cdot 10^5) — the number of elements in the array aa and the number kk.

The second line of each test case 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 aa.

Additional constraints on the input:

  • 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 和 kk(1≤k<n≤2⋅1051 \le k \lt n \le 2 \cdot 10^5)—— 分别表示数组 aa 的元素个数和数值 kk。

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

输入的额外约束条件:

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

输出格式

For each test case, print one integer — the number of kk-balanced subarrays in the array aa.

对于每个测试用例,输出一个整数——数组 aa 中 kk-平衡子数组的个数。

输入输出样例

  • 输入#1

    3
    5 2
    2 1 3 1 4
    9 3
    1 1 1 1 1 1 1 1 1
    4 3
    2 8 5 7

    输出#1

    2
    5
    0

说明/提示

In the first test case of the example, the suitable subarrays are:

  1. [2,1,3][2, 1, 3] (the sum of all elements 2+1+3=62 + 1 + 3 = 6 is divisible by 22);
  2. [3,1,4][3, 1, 4] (the sum of all elements 3+1+4=83 + 1 + 4 = 8 is divisible by 22).

In the second test case, all elements are equal to 11, and k=3k = 3. The suitable subarrays have lengths 66 and 99: there are four subarrays of length 66 and one subarray of length 99, so the answer is 55.

In the third test case, the only subarray of length strictly greater than 33 is the entire array. Its sum is 2222, which is not divisible by 33, so the answer is 00.

在示例的第一个测试用例中,满足条件的子数组有:

  1. [2,1,3][2, 1, 3](所有元素之和 2+1+3=62 + 1 + 3 = 6 能被 22 整除);
  2. [3,1,4][3, 1, 4](所有元素之和 3+1+4=83 + 1 + 4 = 8 能被 22 整除)。

在第二个测试用例中,所有元素均为 11,且 k=3k = 3。满足条件的子数组长度为 66 和 99:长度为 66 的子数组有 44 个,长度为 99 的子数组有 11 个,因此答案为 55。

在第三个测试用例中,唯一长度严格大于 33 的子数组是整个数组。其元素和为 2222,不能被 33 整除,因此答案为 00。

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

首页