1 #define _for(i,a,b) for(int i = (a);i < (b);i ++) 2 #define pb push_back 3 4 class Solution 5 { 6 public: 7 vector<int> sumEvenAfterQueries(vector<int>& A, vector<vector<int>>& queries) 8 { 9 vector<int> rnt; 10 int rntEle = 0; 11 _for(i,0,A.size()) 12 if((A[i]&0x1)==0) 13 rntEle += A[i]; 14 for(int i = 0;i < queries.size();i ++) 15 { 16 if((A[queries[i][1]]&0x1) && ((A[queries[i][1]]+queries[i][0])&0x1)) 17 { 18 A[queries[i][1]] += queries[i][0]; 19 rnt.pb(rntEle); 20 } 21 else if((A[queries[i][1]]&0x1)==0 && ((A[queries[i][1]]+queries[i][0])&0x1)==0) 22 { 23 rntEle += queries[i][0]; 24 A[queries[i][1]] += queries[i][0]; 25 26 rnt.pb(rntEle); 27 } 28 else if((A[queries[i][1]]&0x1) && ((A[queries[i][1]]+queries[i][0])&0x1)==0) 29 { 30 rntEle += A[queries[i][1]]+queries[i][0]; 31 A[queries[i][1]] += queries[i][0]; 32 rnt.pb(rntEle); 33 } 34 else 35 { 36 rntEle -= A[queries[i][1]]; 37 A[queries[i][1]] += queries[i][0]; 38 39 rnt.pb(rntEle); 40 } 41 42 } 43 return rnt; 44 } 45 };