PrefixSum returns the sum of the prefix ending at position pos.
(pos int)
| 35 | |
| 36 | // PrefixSum returns the sum of the prefix ending at position pos. |
| 37 | func (f *FenwickTree) PrefixSum(pos int) int { |
| 38 | if pos > f.n { |
| 39 | return 0 |
| 40 | } |
| 41 | prefixSum := 0 |
| 42 | for i := pos; i > 0; i -= (i & -i) { |
| 43 | prefixSum += f.bit[i] |
| 44 | } |
| 45 | return prefixSum |
| 46 | } |
| 47 | |
| 48 | // RangeSum returns the sum of the elements in the range l to r |
| 49 | // both inclusive. |
no outgoing calls