classSolution:defsumEvenAfterQueries(self, A: List[int], queries: List[List[int]])-> List[int]:
S =sum(item for item in A if item%2==0)
sum_even =[]for item in queries:
index = item[1]# 如果选到该元素,则先剔除if A[index]%2==0:
S -= A[index]
A[index]+= item[0]# 如果改变后是偶数,则添加if A[index]%2==0:
S += A[index]
sum_even.append(S)return sum_even
题目1题解1class Solution: def sumEvenAfterQueries(self, A: List[int], queries: List[List[int]]) -> List[int]: S = sum(item for item in A if item%2==0) sum_even = [] for item in queries: index = item[1]