2536. Increment Submatrices by One Medium

@problem@discussion
#Array#Matrix#Prefix Sum



1/**
2 * [2536] Increment Submatrices by One
3 *
4 * You are given a positive integer n, indicating that we initially have an n x n 0-indexed integer matrix mat filled with zeroes.
5 * You are also given a 2D integer array query. For each query[i] = [row1i, col1i, row2i, col2i], you should do the following operation:
6 * 
7 * 	Add 1 to every element in the submatrix with the top left corner (row1i, col1i) and the bottom right corner (row2i, col2i). That is, add 1 to mat[x][y] for for all row1i <= x <= row2i and col1i <= y <= col2i.
8 * 
9 * Return the matrix mat after performing every query.
10 *  
11 * <strong class="example">Example 1:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2022/11/24/p2example11.png" style="width: 531px; height: 121px;" />
13 * Input: n = 3, queries = [[1,1,2,2],[0,0,1,1]]
14 * Output: [[1,1,0],[1,2,1],[0,1,1]]
15 * Explanation: The diagram above shows the initial matrix, the matrix after the first query, and the matrix after the second query.
16 * - In the first query, we add 1 to every element in the submatrix with the top left corner (1, 1) and bottom right corner (2, 2).
17 * - In the second query, we add 1 to every element in the submatrix with the top left corner (0, 0) and bottom right corner (1, 1).
18 * 
19 * <strong class="example">Example 2:
20 * <img alt="" src="https://assets.leetcode.com/uploads/2022/11/24/p2example22.png" style="width: 261px; height: 82px;" />
21 * Input: n = 2, queries = [[0,0,1,1]]
22 * Output: [[1,1],[1,1]]
23 * Explanation: The diagram above shows the initial matrix and the matrix after the first query.
24 * - In the first query we add 1 to every element in the matrix.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= n <= 500
30 * 	1 <= queries.length <= 10^4
31 * 	0 <= row1i <= row2i < n
32 * 	0 <= col1i <= col2i < n
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/increment-submatrices-by-one/
38// discuss: https://leetcode.com/problems/increment-submatrices-by-one/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn range_add_queries(n: i32, queries: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
44        vec![]
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_2536() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.