JavaScript - Binary Index Tree
js\nfunction NumArray(nums) {\n  const N = nums.length;\n  const dp = Array(N+1).fill(0);\n  const vals = Array(N).fill(0);\n  for (let i = 0; i < N; i++) {\n  
```js\nfunction NumArray(nums) {\n  const N = nums.length;\n  const dp = Array(N+1).fill(0);\n  const vals = Array(N).fill(0);\n  for (let i = 0; i < N; i++) {\n    update(i, nums[i]);\n  }\n  \n  return { update, sumRange };\n  \n  function update(i, v) {\n    let delta = v - vals[i];\n    vals[i] = v;\n    for (let idx = i+1; idx <= N; idx += -idx&idx) {\n      dp[idx] += delta;\n    }\n  }\n  \n  function sumRange(i, j) {\n    return getSum(j) - getSum(i-1);\n  }\n  \n  function getSum(i) {\n    let sum = 0;\n    for (let idx = i + 1; idx >= 1; idx -= -idx&idx) {\n      sum += dp[idx];\n    }\n    \n    return sum;\n  }  \n}\n```
[]