2569. Handling Sum Queries After Update Hard
1/**
2 * [2569] Handling Sum Queries After Update
3 *
4 * You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries:
5 * <ol>
6 * For a query of type 1, queries[i] = [1, l, r]. Flip the values from 0 to 1 and from 1 to 0 in nums1 from index l to index r. Both l and r are 0-indexed.
7 * For a query of type 2, queries[i] = [2, p, 0]. For every index 0 <= i < n, set nums2[i] = nums2[i] + nums1[i] * p.
8 * For a query of type 3, queries[i] = [3, 0, 0]. Find the sum of the elements in nums2.
9 * </ol>
10 * Return an array containing all the answers to the third type queries.
11 *
12 * <strong class="example">Example 1:
13 *
14 * Input: nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]]
15 * Output: [3]
16 * 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.
17 *
18 * <strong class="example">Example 2:
19 *
20 * Input: nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]]
21 * Output: [5]
22 * Explanation: After the first query, nums2 remains [5], so the answer to the second query is 5. Thus, [5] is returned.
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= nums1.length,nums2.length <= 10^5
28 * nums1.length = nums2.length
29 * 1 <= queries.length <= 10^5
30 * <font face="monospace">queries[i].length = 3</font>
31 * <font face="monospace">0 <= l <= r <= nums1.length - 1</font>
32 * <font face="monospace">0 <= p <= 10^6</font>
33 * 0 <= nums1[i] <= 1
34 * 0 <= nums2[i] <= 10^9
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/handling-sum-queries-after-update/
40// discuss: https://leetcode.com/problems/handling-sum-queries-after-update/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn handle_query(nums1: Vec<i32>, nums2: Vec<i32>, queries: Vec<Vec<i32>>) -> Vec<i64> {
46
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_2569() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.