def count_subarray_sum_to_targets(nums: List[int], k: int) -> int:
prefixes = defaultdict(int)
prefixes[0] = 1 # empty array is a subarray of sum 0
current = 0
counts = 0
for num in nums:
current += num
counts += prefixes[current - k]
prefixes[current] += 1
return counts