Video Explanation (EVERYTHING involved here from scratch)
Explanation\n\nClick here for the video\n\n# Code\n\n## My Code (Accepted but not green :P)\n\n\ntypedef long long int ll;\n\nconst int MOD = 1e9+7;\n\nstruct N
# Explanation\n\n[Click here for the video](https://youtu.be/kT7y8D-Xd5g)\n\n# Code\n\n## My Code (Accepted but not green :P)\n\n```\ntypedef long long int ll;\n\nconst int MOD = 1e9+7;\n\nstruct Node {\n    vector<vector<ll>> val;\n    \n    Node() {\n        val.resize(2, vector<ll>(2, 0));\n    }\n};\n\nNode Merge (const Node& lft_node, const Node& rgt_node) {\n    Node ans;\n    \n    for (int lft = 0; lft < 2; lft ++) {\n        for (int rgt = 0; rgt < 2; rgt ++) {   \n            \n            for (int lft_opt = 0; lft_opt < 2; lft_opt ++) \n                ans.val[lft][rgt] = max (\n                    ans.val[lft][rgt], \n                    lft_node.val[lft][lft_opt] + rgt_node.val[1-lft_opt][rgt]\n                );\n        }\n    }\n    return ans;\n}\n\nstruct SegTree {\n    \n    vector<Node> tree;\n    int n;\n    \n    SegTree (int _n, const vector<int>& v) : n(_n) {\n        tree.resize(4*n);\n        build (0, n-1, 0, v);\n    }\n    \n    void build (int l, int r, int i, const vector<int>& v) {\n        if (l == r) {\n            tree[i].val[1][1] = v[l];\n            return;\n        }\n        \n        int m = (l+r) >> 1;\n        build (l, m, i*2+1, v);\n        build (m+1, r, i*2+2, v);\n        \n        tree[i] = Merge(tree[i*2+1], tree[i*2+2]);\n    }\n    \n    void update(int pos, int val, int l = 0, int r = -1, int i = 0) {\n        if (r == -1) r += n;\n        if (l == r) {\n            tree[i].val[1][1] = val;\n            return;\n        }\n        \n        int m = (l+r) >> 1;\n        if (pos <= m) update(pos, val, l, m, i*2+1);\n        else update(pos, val, m+1, r, i*2+2);\n        \n        tree[i] = Merge(tree[i*2+1], tree[i*2+2]);\n    }\n    \n    Node query (int x, int y, int l = 0, int r = -1, int i = 0) {\n        if (r == -1) r += n;\n        if (r < x || l > y) return Node();\n        if (l >= x && r <= y) return tree[i];\n        \n        int m = (l+r) >> 1;\n        return Merge(\n            query(x, y, l, m, i*2+1),\n            query(x, y, m+1, r, i*2+2)\n        );\n    }\n};\n\nclass Solution {\n    \npublic:\n    int maximumSumSubsequence(vector<int>& nums, vector<vector<int>>& queries) {\n        int n = nums.size();\n        SegTree tree(n, nums);\n        \n        ll ans = 0;\n        for (auto q: queries) {\n            tree.update(q[0], q[1]);\n            \n            Node node = tree.query(0, n-1);\n            ll result = 0;\n            for (int i = 0; i < 2; i ++)\n                for (int j = 0; j < 2; j ++)\n                    result = max(result, node.val[i][j]);\n            \n            ans += result;\n        }\n        return ans % MOD;\n    }\n};\n```\n\n## Sample "similar" Accepted code (not mine)\n```\ntemplate<typename T>\nstruct segtree {\n    vector<T> t;\n    int n;\n    segtree(int n): n(n) {\n        t.assign(2 * n, T());\n    }\n    void update(int p, T v){\n        for(t[p += n] = v; p >>= 1; )\n            t[p] = t[p<<1] + t[p<<1|1];\n    }\n    void add(int p, T v){\n        p += n;\n        t[p] = t[p] + v;\n        while(p >>= 1) t[p] = t[p<<1] + t[p<<1|1];\n    }\n    T query(int l, int r){\n        T cl = T(), cr = T();\n        for(l += n, r += n; l < r; l >>= 1, r >>= 1){\n            if(l&1) cl = cl + t[l++];\n            if(r&1) cr = t[--r] + cr;\n        }\n        return cl + cr;\n    }\n};\nusing ll = long long;\nconst ll inf = 1ll<<60;\nstruct node {\n      ll x[2][2];\n    node(){\n        memset(x, 0, sizeof(x));\n    }\n    node(int v){\n        memset(x, 0, sizeof(x));\n        x[1][1] = v;\n    }\n};\n\nnode operator + (node a, node b){\n    node ans;\n    for(int i = 0; i < 2; i++){\n        for(int j = 0; j < 2; j++){\n            for(int k = 0; k < 2; k++){\n                if(k && j) continue;\n                for(int l = 0; l < 2; l++){\n                    ans.x[i][l] = max(ans.x[i][l], a.x[i][j] + b.x[k][l]);\n                }\n            }\n        }\n    }\n    return ans;\n}\n\nclass Solution {\npublic:\n    int maximumSumSubsequence(vector<int>& a, vector<vector<int>>& qe) {\n        int n = a.size();\n        segtree<node> seg(n);\n        for(int i = 0; i < n; i++) seg.update(i, node(a[i]));\n        ll res = 0;\n        int q = qe.size();\n        for(int i = 0; i < q; i++){\n            int p = qe[i][0], v = qe[i][1];\n            seg.update(p, node(v));\n            node ans = seg.query(0, n);\n            ll best = 0;\n            for(int j = 0; j < 2; j++) for(int k = 0; k < 2; k++) best = max(best, ans.x[j][k]);\n            res += best;\n            res %= 1000000007;\n        }\n        return res;\n    }\n};\n```
['C++']