[java] standard segment tree implementation
\nclass NumArray {\n    private int[] st;\n    private int n;\n    private int[] nums;\n    public NumArray(int[] nums) {\n        this.n = nums.length;\n      
```\nclass NumArray {\n    private int[] st;\n    private int n;\n    private int[] nums;\n    public NumArray(int[] nums) {\n        this.n = nums.length;\n        this.st = new int[4*this.n];\n        this.nums = nums;\n        construct(0, this.n-1, 0);\n    }\n    \n    private int construct(int s, int e, int idx) {\n        if (s > e) return 0;\n        if (s == e) {\n            st[idx] = nums[s];\n            return st[idx];\n        }\n        int mid = s + (e-s)/2;\n        st[idx] = construct(s, mid, 2*idx+1) + construct(mid+1, e, 2*idx+2);\n        return st[idx];\n    }\n    \n    public void update(int index, int val) {\n        if (index < 0 || index >= this.n) return;\n        int diff = val - this.nums[index];\n        this.nums[index] = val;\n        updateUtil(0, this.n-1, 0, index, diff);\n    }\n    \n    private void updateUtil(int s, int e, int idx, int i, int diff) {\n        if (i < s || i > e) return;\n        st[idx] += diff;\n        if (s != e) {\n            int mid = s + (e-s)/2;\n            updateUtil(s, mid, 2*idx+1, i, diff);\n            updateUtil(mid+1, e, 2*idx+2, i, diff);\n        }\n    }\n    \n    public int sumRange(int left, int right) {\n        if (left > right || left < 0 || right >= this.n) return 0;\n        return sumRangeUtil(0, this.n-1, 0, left, right);\n    }\n    \n    private int sumRangeUtil(int s, int e, int idx, int qs, int qe) {\n        if (qs > e || qe < s) {\n            return 0;\n        }\n        if (s >= qs && e <= qe) {\n            return st[idx];\n        }\n        int mid = s + (e-s)/2;\n        int res = sumRangeUtil(s, mid, 2*idx+1, qs, qe) + sumRangeUtil(mid+1, e, 2*idx+2, qs,  qe);\n        return res;\n    }\n}\n```
['Tree', 'Java']