1
var NumArray = function (nums) {4
this.fenwickTree = new Array(this.n + 1).fill(0);5
nums.forEach((num, index) => this.init(index, num));8
NumArray.prototype.init = function (index, val) {11
this.fenwickTree[j] += val;16
NumArray.prototype.lsb = function (index) {17
return index & ~(index - 1);20
NumArray.prototype.update = function (index, val) {21
const diff = val - this.nums[index];22
this.nums[index] = val;23
this.init(index, diff);26
NumArray.prototype.getSum = function (index) {31
sum += this.fenwickTree[j];38
NumArray.prototype.sumRange = function (left, right) {39
return this.getSum(right) - this.getSum(left - 1);