<awangdev>327. Count of Range Sum_1.java
private int mergeSort(long[] preSum, int lower, int upper, int start, int end) {

        if (start + 1 >= end) return 0;
        int mid = (start + end) / 2, count = 0;
        
        count += mergeSort(preSum, lower, upper, start, mid);
        count += mergeSort(preSum, lower, upper, mid, end);
        
        int lo = mid, hi = mid; 
        for (int i = start; i < mid; i++) {
            while (lo < end && preSum[lo] - preSum[i] < lower) lo++;
            while (hi < end && preSum[hi] - preSum[i] <= upper) hi++;
            count += hi - lo;
        }

        Arrays.sort(preSum, start, end);
        return count;
    }
private int sample_funcname ( long [ ] preSum , int lower , int upper , int start , int end ) {
  if ( start + 1 >= end ) return 0 ;
  int mid = ( start + end ) / 2 , count = 0 ;
  count += mergeSort ( preSum , lower , upper , start , mid ) ;
  count += mergeSort ( preSum , lower , upper , mid , end ) ;
  int lo = mid , hi = mid ;
  for ( int i = start ;
  i < mid ;
  i ++ ) {
    while ( lo < end && preSum [ lo ] - preSum [ i ] < lower ) lo ++ ;
    while ( hi < end && preSum [ hi ] - preSum [ i ] <= upper ) hi ++ ;
    count += hi - lo ;
  }
  Arrays . sort ( preSum , start , end ) ;
  return count ;
}
