#P5459. Sushi Satisfaction Count
Sushi Satisfaction Count
Sushi Satisfaction Count
Little Z is a huge fan of Japanese cuisine and often visits the conveyor belt sushi restaurant outside the East Gate of his school. At the restaurant, N plates of sushi pass before him sequentially on a conveyor belt. Each sushi plate has a satisfaction value associated with it. For instance, Little Z loves salmon with a satisfaction of 10, finds tuna mediocre with 5, and is repelled by octopus sashimi scoring -100.
When Little Z starts eating a plate, he will continue eating every subsequent plate without hesitation until he decides to stop. In other words, he selects a contiguous subarray of the sushi sequence to consume. Given the satisfaction values of the plates, determine how many different contiguous segments (i.e. choices of starting and ending plate) have a total satisfaction sum between L and R (inclusive).
Note: Even though the sushi plates are on a conveyor belt, the problem is linear, not circular.
inputFormat
The first line contains three integers N
, L
and R
(1 ≤ N ≤ 105, -109 ≤ L ≤ R ≤ 109), representing the number of sushi plates and the lower and upper bounds of the satisfaction sum, respectively.
The second line contains N
integers a1, a2, ..., aN
(each satisfying |ai| ≤ 109), where ai
is the satisfaction of the i-th sushi plate.
outputFormat
Output a single integer, the number of contiguous subarrays whose total satisfaction sum is between L and R (inclusive).
sample
3 5 15
10 5 -100
3