class Solution:
def handleQuery(self, nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:
ans = []
n1 = int(''.join([str(d) for d in nums1]), 2)
sum1, sum2 = n1.bit_count(), sum(nums2)
for t, left, right in queries:
if t == 1:
n1 ^= int('1' * (right - left + 1) + '0' * (len(nums1) - right - 1), 2)
elif t == 2:
sum1 = n1.bit_count()
sum2 += left * sum1
else:
ans.append(sum2)
return ans