17 ms Java solution with segment tree
public class NumArray {\n    \n        class SegmentTreeNode {\n            int start, end;\n            SegmentTreeNode left, right;\n            int sum;\n   
    public class NumArray {\n    \n        class SegmentTreeNode {\n            int start, end;\n            SegmentTreeNode left, right;\n            int sum;\n    \n            public SegmentTreeNode(int start, int end) {\n                this.start = start;\n                this.end = end;\n                this.left = null;\n                this.right = null;\n                this.sum = 0;\n            }\n        }\n          \n        SegmentTreeNode root = null;\n       \n        public NumArray(int[] nums) {\n            root = buildTree(nums, 0, nums.length-1);\n        }\n    \n        private SegmentTreeNode buildTree(int[] nums, int start, int end) {\n            if (start > end) {\n                return null;\n            } else {\n                SegmentTreeNode ret = new SegmentTreeNode(start, end);\n                if (start == end) {\n                    ret.sum = nums[start];\n                } else {\n                    int mid = start  + (end - start) / 2;             \n                    ret.left = buildTree(nums, start, mid);\n                    ret.right = buildTree(nums, mid + 1, end);\n                    ret.sum = ret.left.sum + ret.right.sum;\n                }         \n                return ret;\n            }\n        }\n       \n        void update(int i, int val) {\n            update(root, i, val);\n        }\n       \n        void update(SegmentTreeNode root, int pos, int val) {\n            if (root.start == root.end) {\n               root.sum = val;\n            } else {\n                int mid = root.start + (root.end - root.start) / 2;\n                if (pos <= mid) {\n                     update(root.left, pos, val);\n                } else {\n                     update(root.right, pos, val);\n                }\n                root.sum = root.left.sum + root.right.sum;\n            }\n        }\n    \n        public int sumRange(int i, int j) {\n            return sumRange(root, i, j);\n        }\n        \n        public int sumRange(SegmentTreeNode root, int start, int end) {\n            if (root.end == end && root.start == start) {\n                return root.sum;\n            } else {\n                int mid = root.start + (root.end - root.start) / 2;\n                if (end <= mid) {\n                    return sumRange(root.left, start, end);\n                } else if (start >= mid+1) {\n                    return sumRange(root.right, start, end);\n                }  else {    \n                    return sumRange(root.right, mid+1, end) + sumRange(root.left, start, mid);\n                }\n            }\n        }\n    }
[]