Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // calculate the number of non-empty segment which sums to a value >= 0
- int sol(const vector<int>& a) {
- int ans = 0;
- int acc = 0;
- // for definition of add() and sum(), please refer to
- // http://www.csie.ntnu.edu.tw/~u91029/Sequence2.html#4
- add(0, 1);
- for (auto v: a) {
- acc += v;
- ans += sum(acc);
- add(acc, 1);
- }
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement