<p>You are given an integer array <code>nums</code> and an array <code>queries</code> where <code>queries[i] = [val<sub>i</sub>, index<sub>i</sub>]</code>.</p>

<p>For each query <code>i</code>, first, apply <code>nums[index<sub>i</sub>] = nums[index<sub>i</sub>] + val<sub>i</sub></code>, then print the sum of the even values of <code>nums</code>.</p>

<p>Return <em>an integer array </em><code>answer</code><em> where </em><code>answer[i]</code><em> is the answer to the </em><code>i<sup>th</sup></code><em> query</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]
<strong>Output:</strong> [8,6,2,4]
<strong>Explanation:</strong> At the beginning, the array is [1,2,3,4].
After adding 1 to nums[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.
After adding -3 to nums[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.
After adding -4 to nums[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.
After adding 2 to nums[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1], queries = [[4,0]]
<strong>Output:</strong> [0]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
	<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
	<li><code>1 &lt;= queries.length &lt;= 10<sup>4</sup></code></li>
	<li><code>-10<sup>4</sup> &lt;= val<sub>i</sub> &lt;= 10<sup>4</sup></code></li>
	<li><code>0 &lt;= index<sub>i</sub> &lt; nums.length</code></li>
</ul>

class Solution {
    int seg[400004]={0};
    void build(int node,int start,int end,vector<int> &nums){
        if(start==end) {
            if(nums[start]%2==0) seg[node]=nums[start];
            
            return;
        }
        int mid=start+(end-start)/2;
        build(node*2+1,start,mid,nums);
        build(node*2+2,mid+1,end,nums);
        if(seg[node*2+1]%2==0) seg[node]+=seg[node*2+1];
        if(seg[node*2+2]%2==0) seg[node]+=seg[node*2+2];
    }
    void update(int node,int start,int end,vector<int> & nums,int pos,int val){
        if(start==end){
            seg[node]=0;
            nums[start]+=val;
            //cout<<nums[start]<<endl;
            if(nums[start]%2==0) seg[node]=nums[start];
            return;
        }
        int mid=start+(end-start)/2;
        if(pos<=mid) update(2*node+1,start,mid,nums,pos,val);
        else update(2*node+2,mid+1,end,nums,pos,val);
        seg[node]=0;
        if(seg[node*2+1]%2==0) seg[node]+=seg[node*2+1];
        if(seg[node*2+2]%2==0) seg[node]+=seg[node*2+2];
        return ;
    }
public:
    vector<int> sumEvenAfterQueries(vector<int>& nums, vector<vector<int>>& queries) {
            build(0,0,nums.size()-1,nums);
        vector<int> ans;
        cout<<seg[0]<<endl;
        for(int i=0;i<queries.size();i++){
            update(0,0,nums.size()-1,nums,queries[i][1],queries[i][0]);
            ans.push_back(seg[0]);
        }
        // for(int i=0;i<nums.size();i++){
        //     cout<<nums[i]<<endl;
        // }
        return ans;
    }
};
51500