#C3197. Count Special Contiguous Subsequences
Count Special Contiguous Subsequences
Count Special Contiguous Subsequences
You are given an array of N integers and an integer X. Your task is to count the number of special contiguous subsequences (i.e. subarrays) whose sum is exactly equal to X.
A contiguous subsequence is a sequence of consecutive elements from the array. Mathematically, for a subarray defined by indices l and r (using 1-indexing), its sum is represented by:
Your solution should be efficient enough to handle large inputs.
inputFormat
The first line contains two space separated integers N
and X
.
The second line contains N
space separated integers representing the array A
.
Note: N
is the number of elements in the array and X
is the target sum.
outputFormat
Output a single integer which is the number of contiguous subsequences whose sum equals X
.
5 5
1 2 3 4 5
2