JS
Code\n\nclass Tree {\n    constructor(n) {\n        this.nn = n;\n        this.space = new Array(4 * n + 1).fill(null).map(() => ({ mx: [[0, -0x1ffffffffffff], 
# Code\n```\nclass Tree {\n    constructor(n) {\n        this.nn = n;\n        this.space = new Array(4 * n + 1).fill(null).map(() => ({ mx: [[0, -0x1ffffffffffff], [-0x1ffffffffffff, 0]] }));\n        for (; ;) {\n            let low_bit = this.nn & -this.nn;\n            if (low_bit == this.nn) {\n                break;\n            }\n            this.nn += low_bit;\n        }\n    }\n\n    modify(index, sl, sr, q, qv) {\n        let v = this.space[index];\n        if (sl + 1 == sr) {\n            v.mx = [\n                [0, -0x1ffffffffffff],\n                [-0x1ffffffffffff, qv]\n            ];\n            return;\n        }\n        let m = (sl + sr) >> 1;\n        if (q < m) {\n            this.modify(index * 2, sl, m, q, qv);\n        } else {\n            this.modify(index * 2 + 1, m, sr, q, qv);\n        }\n        let l = this.space[index * 2];\n        let r = this.space[index * 2 + 1];\n        for (let lb of [0, 1]) {\n            for (let rb of [0, 1]) {\n                let ans = -0x1ffffffffffff;\n                ans = Math.max(ans, l.mx[lb][1] + r.mx[0][rb]);\n                ans = Math.max(ans, l.mx[lb][0] + r.mx[1][rb]);\n                ans = Math.max(ans, l.mx[lb][0] + r.mx[0][rb]);\n                v.mx[lb][rb] = ans;\n            }\n        }\n    }\n\n    query() {\n        let v = this.space[1];\n        let ans = -0x1ffffffffffff;\n        for (let i = 0; i < 2; i++) {\n            for (let j = 0; j < 2; j++) {\n                ans = Math.max(ans, v.mx[i][j]);\n            }\n        }\n        return ans;\n    }\n}\n\nvar maximumSumSubsequence = function (nums, queries) {\n    const ninf = -0x1ffffffffffff;\n    const mod = 1000000007;\n    const n = nums.length;\n    let tree = new Tree(n);\n\n    for (let i = 0; i < n; ++i) {\n        tree.modify(1, 0, tree.nn, i, nums[i]);\n    }\n    for (let i = n; i < tree.nn; ++i) {\n        tree.modify(1, 0, tree.nn, i, 0);\n    }\n\n    let ans = 0;\n\n    for (let q of queries) {\n        let pos = q[0];\n        let x = q[1];\n        tree.modify(1, 0, tree.nn, pos, x);\n        ans += mod + tree.query() % mod; // [0, 2*mod)\n    }\n\n    ans %= mod;\n    return ans;\n};\n\n```
['JavaScript']