Java. Segment Tree. Using Arrays
\nclass NumArray {\n\n    int[] segment;\n    int n;\n    \n    public NumArray(int[] nums) {\n        this.n = nums.length;\n        this.segment = new int[4 *
```\nclass NumArray {\n\n    int[] segment;\n    int n;\n    \n    public NumArray(int[] nums) {\n        this.n = nums.length;\n        this.segment = new int[4 * n];\n        makeSegmentTree(nums, 1, 0, n - 1);\n    }\n    \n    private void makeSegmentTree(int[] nums, int pos, int start, int end){\n        if(start == end){\n            this.segment[pos] = nums[start];\n            return;\n        }\n        \n        int mid = start + (end - start) / 2;\n        makeSegmentTree(nums, 2 * pos, start, mid);\n        makeSegmentTree(nums, 2 * pos + 1, mid + 1, end);\n        \n        segment[pos] = segment[2 * pos] + segment[2 * pos + 1];\n    }\n    \n    public void update(int index, int val) {\n        updateHelper(1, 0, n - 1, index, val);\n    }\n    \n    private void updateHelper(int pos, int start, int end, int idx, int val){\n        if(start == end){\n            segment[pos] = val;\n            return;\n        }\n        \n        int mid = start + (end - start) / 2;\n        if(idx <= mid)\n            updateHelper(2 * pos, start, mid, idx, val);\n        else \n            updateHelper(2 * pos + 1, mid + 1, end, idx, val);\n        segment[pos] = segment[2 * pos] + segment[2 * pos + 1]; \n    }\n    \n    public int sumRange(int left, int right) {\n        return sumRangeHelper(1, 0, n - 1, left, right);\n    }\n    \n    private int sumRangeHelper(int pos, int start, int end, int left, int right){\n        if(left <= start && right >= end)\n            return segment[pos];\n        \n        if(left > end || right < start)\n            return 0;\n        \n        int mid = start + (end - start) / 2;\n        int l = sumRangeHelper(2 * pos, start, mid, left, right);\n        int r = sumRangeHelper(2 * pos + 1, mid + 1, end, left, right);\n        return l + r;\n    }\n}\n```
['Array', 'Tree', 'Java']