#C5201. Subarray Sum

    ID: 48825 Type: Default 1000ms 256MiB

Subarray Sum

Subarray Sum

This problem requires you to find the number of contiguous subarrays within a given array whose sum equals a specified target k. A subarray is defined as a contiguous sequence of elements within an array. To solve this efficiently, you may consider using cumulative sums and hashing techniques. In particular, if you define \(S_i\) as the cumulative sum up to the \(i\)-th element, then the sum of the subarray from index \(i+1\) to \(j\) can be computed as \(S_j - S_i\). Your task is to read input from stdin and output the answer for each test case to stdout.

inputFormat

The input is given via stdin and is formatted as follows:

  1. The first line contains an integer \(T\), the number of test cases.
  2. For each test case, the first line contains two space-separated integers \(n\) and \(k\) where \(n\) is the number of elements in the array and \(k\) is the target sum.
  3. The second line of each test case contains \(n\) space-separated integers representing the array elements.

outputFormat

For each test case, print a single integer on a new line representing the number of subarrays whose sum is equal to \(k\). The output should be sent to stdout.

## sample
3
3 2
1 1 1
4 0
1 2 -2 3
4 0
1 -1 1 -1
2

1 4

</p>