Simple Approach || Constant Space
\n# Approach\n- We start by defining a function named findMaxNonAdjSum. This function traverses the array, calculating the maximum sum of a subsequence where no
\n# Approach\n- We start by defining a function named findMaxNonAdjSum. This function traverses the array, calculating the maximum sum of a subsequence where no two adjacent elements are selected. We achieve this using dynamic programming.\n- In the main function maximumSumSubsequence, we handle each query by updating the value at the specified index in the array and recalculating the maximum sum using the findMaxNonAdjSum function. We keep track of these sums while ensuring they don\'t exceed the specified modulo value to handle large results.\n- Finally, we return the total sum of maximum non-adjacent subsequence sums over all queries, considering the modulo operation to prevent integer overflow.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(arr.length * qs.length)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    static const int MOD_VAL = 1e9 + 7;\n\n    long findMaxNonAdjSum(vector<int>& arr) {\n        long inclCurr = 0, exclCurr = 0;\n        for (int elem : arr) {\n            long newInclCurr = exclCurr + elem;\n            exclCurr = max(exclCurr, inclCurr);\n            inclCurr = newInclCurr;\n        }\n        return max(inclCurr, exclCurr);\n    }\n\n    int maximumSumSubsequence(vector<int>& arr, vector<vector<int>>& qs) {\n        long cumulativeSum = 0;\n        long maxNonAdjSum = findMaxNonAdjSum(arr);\n\n        for (vector<int>& q : qs) {\n            int index = q[0];\n            int value = q[1];\n\n            arr[index] = value;\n            maxNonAdjSum = findMaxNonAdjSum(arr);\n            cumulativeSum = (cumulativeSum + maxNonAdjSum) % MOD_VAL;\n        }\n\n        return static_cast<int>(cumulativeSum);\n    }\n};\n\n```\n```Java []\nclass Solution {\n    static final int MOD_VAL = 1_000_000_007;\n\n    public static long findMaxNonAdjSum(int[] arr) {\n        long inclCurr = 0, exclCurr = 0;\n        for (int elem : arr) {\n            long newInclCurr = exclCurr + elem;\n            exclCurr = Math.max(exclCurr, inclCurr);\n            inclCurr = newInclCurr;\n        }\n        return Math.max(inclCurr, exclCurr);\n    }\n\n    public static int maximumSumSubsequence(int[] arr, int[][] qs) {\n        long cumulativeSum = 0;\n        long maxNonAdjSum = findMaxNonAdjSum(arr);\n\n        for (int[] q : qs) {\n            int index = q[0];\n            int value = q[1];\n\n            arr[index] = value;\n            maxNonAdjSum = findMaxNonAdjSum(arr);\n            cumulativeSum = (cumulativeSum + maxNonAdjSum) % MOD_VAL;\n        }\n\n        return (int) cumulativeSum;\n    }\n}\n```
['C++', 'Java']