Javascript segment tree node 594ms
\n////////////////////// modified template /////////////////////////\nfunction SegmentTreeNode(nodeArray) {\n    let newNode = [0, 0, 0, 0], n = nodeArray.lengt
```\n////////////////////// modified template /////////////////////////\nfunction SegmentTreeNode(nodeArray) {\n    let newNode = [0, 0, 0, 0], n = nodeArray.length, h = Math.ceil(Math.log2(n)), len = 2 * 2 ** h, a = Array(len).fill(newNode);\n    initializeFromArray();\n    return { update, query, tree }\n    function initializeFromArray() {\n        for (let i = 0; i < n; i++) a[n + i] = nodeArray[i];\n        for (let i = n - 1; i >= 1; i--) pushup(i);\n    }\n    function update(pos, v) {\n        a[n + pos] = v;\n        for (let i = parent(n + pos); i >= 1; i = parent(i)) pushup(i);\n    }\n    function pushup(i) {\n        a[i] = f(a[left(i)], a[right(i)]);\n    }\n    function query(l, r) { // [L, R)\n        let resL = resR = newNode;\n        if (l >= r) return 0;\n        l += n;\n        r += n;\n        for (; l < r; l = parent(l), r = parent(r)) {\n            if (l & 1) resL = f(resL, a[l++]);\n            if (r & 1) resR = f(a[--r], resR);\n        }\n        return f(resL, resR);\n    }\n    function f(x, y) {\n        /*\n        a: cover first number\n        b: cover last number\n        c: not cover first and last number\n        d: cover both first and last number\n        */\n        let [a1, b1, c1, d1] = x, [a2, b2, c2, d2] = y;\n        return [Math.max(a1 + Math.max(a2, c2), d1 + c2), Math.max(b1 + b2, c1 + Math.max(b2, d2)),\n        Math.max(b1 + c2, c1 + Math.max(a2, c2)), Math.max(a1 + Math.max(d2, b2), d1 + b2)];\n    }\n    function parent(i) {\n        return i >> 1;\n    }\n    function left(i) {\n        return 2 * i;\n    }\n    function right(i) {\n        return 2 * i + 1;\n    }\n    function tree() {\n        return a;\n    }\n}\n////////////////////////////////////////////////////////\n\nconst mod = 1e9 + 7;\n\nconst maximumSumSubsequence = (a, queries) => {\n    let n = a.length, nodeArray = a.map(x => [0, 0, 0, Math.max(0, x)]), st = new SegmentTreeNode(nodeArray), res = 0;\n    for (const [i, x] of queries) {\n        st.update(i, [0, 0, 0, Math.max(0, x)]);\n        res += Math.max(...st.query(0, n));\n        res %= mod;\n    }\n    return res;\n};\n```
['Segment Tree', 'JavaScript']