Share my c++ solution: 1700ms, using tree array
class NumArray {\n    public:\n        NumArray(vector<int> &nums) {\n            sz = nums.size();\n            num = vector<int>(sz+1, 0);\n            sum = 
    class NumArray {\n    public:\n        NumArray(vector<int> &nums) {\n            sz = nums.size();\n            num = vector<int>(sz+1, 0);\n            sum = vector<int>(sz+1, 0);\n            for(int i=0; i<sz; i++) {\n                update(i, nums[i]);\n            }\n            \n        }\n    \n        void update(int idx, int val) {\n            int oldv = num[idx+1];\n            for(int i = idx+1; i<=sz; i+= (i&-i)) {\n                sum[i] = sum[i] - oldv + val;\n            }\n            num[idx+1] = val;\n        }\n    \n        int sumRange(int i, int j) {\n            return getSum(j+1) - getSum(i);\n        }\n        \n        int getSum(int idx) {\n            int ret = 0;\n            for(int i=idx; i>0; i-=(i&-i)) {\n                ret += sum[i];\n            }\n            return ret;\n        }\n    private :\n        int sz;\n        vector<int> num;\n        vector<int> sum;\n    };\n\nlog(n) to update, log(n) to sum
[]