#2569
Handling Sum Queries After Update
international master · 1975 · lc hard +32 · verified · 30.5% accepted · 198 likes · top 8%
Description
You are given binary arrays nums1 and nums2 and a query list with three types: type 1 [1, l, r] flips all bits in nums1[l..r]; type 2 [2, p, 0] adds nums1[i] * p to each nums2[i]; type 3 [3, 0, 0] requests the current sum of nums2. Return the answers to all type-3 queries in order.
Example 1:
Input: nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]]
Output: [3]
Explanation: 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. Thus, [3] is returned.
Example 2:
Input: nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]]
Output: [5]
Explanation: After the first query, nums2 remains [5], so the answer to the second query is 5. Thus, [5] is returned.
Code
1
2
3