Handling Sum Queries After Update
You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries:
- For a query of type
1,queries[i] = [1, l, r]. Flip the values from0to1and from1to0innums1from indexlto indexr. Bothlandrare 0-indexed. - For a query of type
2,queries[i] = [2, p, 0]. For every index0 <= i < n, setnums2[i] = nums2[i] + nums1[i] * p. - For a query of type
3,queries[i] = [3, 0, 0]. Find the sum of the elements innums2.
Return an array containing all the answers to the third type queries.
Example 1
Input
nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]]Output
[3]After the first query nums1 becomes [1,1,1], after the second query nums2 becomes [1,1,1], so the answer to the third query is 3.
Example 2
Input
nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]]Output
[5]After the first query, nums2 remains [5], so the answer to the second query is 5.
Constraints
- 1 <= nums1.length,nums2.length <= 10^5
- nums1.length = nums2.length
- 1 <= queries.length <= 10^5
- queries[i].length = 3
- 0 <= l <= r <= nums1.length - 1
- 0 <= p <= 10^6
- 0 <= nums1[i] <= 1
- 0 <= nums2[i] <= 10^9