Update Query in Segment tree
\n\n# Code\n\nstruct info{\n    int l0r0, l1r0, l0r1, l1r1;\n};\nvoid update(vector<info>& tree, int tidx, int s, int e, int idx, int val){\n    if(s == e){\n  
\n\n# Code\n```\nstruct info{\n    int l0r0, l1r0, l0r1, l1r1;\n};\nvoid update(vector<info>& tree, int tidx, int s, int e, int idx, int val){\n    if(s == e){\n        tree[tidx].l0r0 = tree[tidx].l1r0 = tree[tidx].l0r1 = 0;\n        tree[tidx].l1r1 = val;\n        return;\n    }\n    int mid = (s + e)/2;\n    if(idx <= mid){\n        update(tree, 2*tidx, s, mid, idx, val);\n    }\n    else update(tree, 2*tidx + 1, mid + 1, e, idx, val);\n    tree[tidx].l0r0 = max({tree[2*tidx].l0r1 + tree[2*tidx + 1].l0r0, tree[2*tidx].l0r0 + tree[2*tidx+1].l1r0, tree[2*tidx].l0r0 + tree[2*tidx+1].l0r0});\n    tree[tidx].l0r1 = max({tree[2*tidx].l0r1 + tree[2*tidx + 1].l0r1, tree[2*tidx].l0r0 + tree[2*tidx+1].l1r1, tree[2*tidx].l0r0 + tree[2*tidx+1].l0r1});\n    tree[tidx].l1r0 = max({tree[2*tidx].l1r1 + tree[2*tidx + 1].l0r0, tree[2*tidx].l1r0 + tree[2*tidx+1].l1r0, tree[2*tidx].l1r0 + tree[2*tidx+1].l0r0});\n    tree[tidx].l1r1 = max({tree[2*tidx].l1r1 + tree[2*tidx + 1].l0r1, tree[2*tidx].l1r0 + tree[2*tidx+1].l1r1, tree[2*tidx].l1r0 + tree[2*tidx+1].l0r1});\n}\n\nconst int mod = 1e9 + 7;\nclass Solution {\npublic:\n    int maximumSumSubsequence(vector<int>& v, vector<vector<int>>& query) {\n        int n = v.size();\n        int q = query.size();\n        vector<info> tree(4 * n);\n        for(int i=0;i<n;i++){\n            update(tree, 1, 0, n-1, i, v[i]);\n        }\n        int ans = 0;\n        for(int i=0;i<q;i++){\n            int idx = query[i][0], val = query[i][1];\n            update(tree, 1, 0, n - 1, idx, val);\n            info sol = tree[1];\n            ans = (ans + max({sol.l0r0, sol.l0r1, sol.l1r0, sol.l1r1}) % mod)%mod;\n        }\n        return ans;\n    }\n};\n```
['C++']