Count of Range Sum
HardLeetCodeSegment Tree & Fenwick Tree
Approach hintTry it first, then revealHide
With prefix sums P, count pairs i < j with P[j] - upper <= P[i] <= P[j] - lower. Compress the values and query a Fenwick tree over earlier prefixes, or count the pairs during a merge sort.