Advertisement
Guest User

Untitled

a guest
Jan 31st, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1.  
  2. // calculate the number of non-empty segment which sums to a value >= 0
  3. int sol(const vector<int>& a) {
  4.     int ans = 0;
  5.     int acc = 0;
  6.     // for definition of add() and sum(), please refer to
  7.     // http://www.csie.ntnu.edu.tw/~u91029/Sequence2.html#4
  8.     add(0, 1);
  9.     for (auto v: a) {
  10.         acc += v;
  11.         ans += sum(acc);
  12.         add(acc, 1);
  13.     }
  14.     return ans;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement