a few solutions
Use a binary indexed tree (BIT) for updates + queries in O(logN) time.\n\n---\n\nKotlin\n\nclass NumArray(A: IntArray) {\n    var A: IntArray\n    var S: IntArr
Use a binary indexed tree (BIT) for updates + queries in O(logN) time.\n\n---\n\n*Kotlin*\n```\nclass NumArray(A: IntArray) {\n    var A: IntArray\n    var S: IntArray\n    var N: Int\n    var prev = { i: Int -> i - (i and i.inv() + 1) }\n    var next = { i: Int -> i + (i and i.inv() + 1) }\n    init {\n        this.A = A\n        N = A.size\n        S = IntArray(N + 1) { 0 }\n        for (i in 0 until N) {\n            var k = i + 1\n            while (k <= N) {\n                S[k] += A[i]; k = next(k)\n            }\n        }\n    }\n    fun update(i: Int, x: Int) {\n        var diff = x - A[i]; A[i] = x\n        var k = i + 1\n        while (k <= N) {\n            S[k] += diff; k = next(k)\n        }\n    }\n    fun query(i: Int): Int { return if (0 < i) S[i] + query(prev(i)) else 0 }\n    var sumRange = { i: Int, j: Int -> query(j + 1) - query(i) }\n}\n```\n\n*Javascript*\n```\nclass NumArray {\n    constructor(A) {\n        this.A = [...A];\n        this.N = this.A.length;\n        this.S = Array(this.N + 1).fill(0);\n        for (let i = 0; i < this.N; ++i)\n            for (let k = i + 1; k <= this.N; k = this.next(k))\n                this.S[k] += this.A[i];\n    }\n    update = (i, x) => {\n        let diff = x - this.A[i]; this.A[i] = x;\n        for (let k = i + 1; k <= this.N; k = this.next(k))\n            this.S[k] += diff;\n    }\n    sumRange = (i, j) => this.query(j + 1) - this.query(i);\n    query = i => i ? this.S[i] + this.query(this.prev(i)) : 0;\n    prev = i => i - (i & ~i + 1);\n    next = i => i + (i & ~i + 1);\n}\n```\n\n*Python3*\n```\nclass NumArray:\n    def __init__(self, A: List[int]):\n        self.N = len(A)\n        self.A, self.S = A[:], [0] * (self.N + 1)\n        for i in range(self.N):\n            k = i + 1\n            while k <= self.N:\n                self.S[k] += self.A[i]\n                k = self.next(k)\n\n    def update(self, i: int, x: int) -> None:\n        diff, self.A[i] = x - self.A[i], x\n        k = i + 1\n        while k <= self.N:\n            self.S[k] += diff\n            k = self.next(k)\n\n    query = lambda self, i: self.S[i] + self.query(self.prev(i)) if i else 0\n    sumRange = lambda self, i, j: self.query(j + 1) - self.query(i)\n    prev = lambda self, i: i - (i & -i)\n    next = lambda self, i: i + (i & -i)\n```\n\n*Rust*\n```\n// TODO: implement me!\n```\n\n*C++*\n```\nusing VI = vector<int>;\nclass NumArray {\n    VI A, S; size_t N;\n    int prev(int i) { return i - (i & -i); }\n    int next(int i) { return i + (i & -i); }\n    int query(int i) { return i ? S[i] + query(prev(i)) : 0; }\npublic:\n    NumArray(VI& A) : A{ A }, S{ VI(A.size() + 1) }, N{ A.size() } {\n        for (auto i{ 0 }; i < N; ++i)\n            for (auto k{ i + 1 }; k <= N; k = next(k))\n                S[k] += A[i];\n    }\n    void update(int i, int x) {\n        auto diff = x - A[i]; A[i] = x;\n        for (auto k{ i + 1 }; k <= N; k = next(k))\n            S[k] += diff;\n    }\n    int sumRange(int i, int j) { return query(j + 1) - query(i); }\n};\n```
[]