| 23 | } |
| 24 | |
| 25 | int getSum(vector<int> &tree, int L, int R, int si, int ei, int idx) |
| 26 | { |
| 27 | if (ei < L || si > R) |
| 28 | { |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | if (L <= si && R >= ei) |
| 33 | { |
| 34 | return tree[idx]; |
| 35 | } |
| 36 | |
| 37 | int mid = si + ((ei - si) / 2); |
| 38 | |
| 39 | return getSum(tree, L, R, si, mid, (2 * idx) + 1) + getSum(tree, L, R, mid + 1, ei, (2 * idx) + 2); |
| 40 | } |
| 41 | |
| 42 | int getSum(vector<int> &nums, vector<int> &tree, int L, int R) |
| 43 | { |