SHARE
TWEET

Untitled

a guest May 20th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int Solution::numRange(vector<int> &A, int B, int C) {
  2.     int ans=0,size = A.size();
  3.     vector<long long> prefixSum(size, 0);
  4.     prefixSum[0] = A[0];
  5.     for(int i = 1; i < size; i++) prefixSum[i]= prefixSum[i-1] + A[i];
  6.     int l = 0, r = 0;
  7.     long long value = 0;
  8.     for(int i=0; i < size; i++) {
  9.         value = (i == 0) ? 0 : prefixSum[i-1];
  10.         while(l < size and prefixSum[l] < (value + 1ll*B)) l++;
  11.         while(r < size and prefixSum[r] <= (value + 1ll*C)) r++;
  12.         ans += r - l;
  13.     }
  14.     return ans;
  15. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top