Segment Tree solution using incude-exclude first and last element in c++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    struct node{\n        long long int ex_first=0;\n        long long int ex_last=0;\n        long long int in_first_in_last=0;\n        long long int ex_first_ex_last=0;\n    };\n    node create(int val)\n    {\n        node n;\n        n.ex_first=0;\n        n.ex_last=0;\n        n.in_first_in_last=max(0,val);\n        n.ex_first_ex_last=0;\n        return n;\n    }\n    node merge(node l,node r)\n    {\n        node n;\n        n.ex_first=max({l.ex_first+r.ex_first,l.ex_first_ex_last+r.in_first_in_last});\n        n.ex_last=max({l.ex_last+r.ex_last,l.in_first_in_last+r.ex_first_ex_last});\n        n.in_first_in_last=max({l.ex_last+r.in_first_in_last,l.in_first_in_last+r.ex_first});\n        n.ex_first_ex_last=max({l.ex_first+r.ex_first_ex_last,l.ex_first_ex_last+r.ex_last});\n        return n;\n    }\n    void build(vector<int>&nums,vector<node>&seg,int l,int r,int idx)\n    {\n        if(l==r)\n        {\n            seg[idx]=create(nums[l]);\n            return;\n        }\n        int mid=(l+r)/2;\n        build(nums,seg,l,mid,idx*2+1);\n        build(nums,seg,mid+1,r,idx*2+2);\n        seg[idx]=merge(seg[idx*2+1],seg[idx*2+2]);\n    }\n    void update(vector<node>&seg,int l,int r,int idx,int val,int val_idx)\n    {\n        if(l==r)\n        {\n            seg[idx]=create(val);\n            return;\n        }\n        int mid=(l+r)/2;\n        if(val_idx<=mid)\n        update(seg,l,mid,idx*2+1,val,val_idx);\n        else\n        update(seg,mid+1,r,idx*2+2,val,val_idx);\n        seg[idx]=merge(seg[idx*2+1],seg[idx*2+2]);\n    }\n    int maximumSumSubsequence(vector<int>& nums, vector<vector<int>>& queries) \n    {\n        int n=nums.size();\n        vector<node>seg(4*n+1);\n        build(nums,seg,0,n-1,0);\n        long long int ans=0;\n        for(auto v:queries)\n        {\n            int val=v[1],pos=v[0];\n            update(seg,0,n-1,0,val,pos);\n            ans+=seg[0].in_first_in_last;\n            ans%=(int)(1e9+7);\n        }\n        return ans;\n    }\n};\n```
['C++']