Tap here to switch tabs
Problem
Submissions

Problem: Increment Submatrices by One

Try to solve the Increment Submatrices by One problem.

Statement

You are given a positive integer n, representing an n×nn \times n 00-indexed integer matrix mat initialized with all 00s.

You are also given a 22D integer array queries, where queries[i] =[row1i,col1i,row2i,col2i]= [\text{row1}_i, \text{col1}_i, \text{row2}_i, \text{col2}_i]. For each query, you must increment every cell mat[r][c] by 11 for all r and c such that row1i≤r≤row2i\text{row1}_i \leq r \leq \text{row2}_i and col1i≤c≤col2i\text{col1}_i \leq c \leq \text{col2}_i.

Return the matrix mat after processing all the queries.

Constraints:

  • 1≤1 \leq n ≤500\leq 500

  • 1≤1 \leq queries.length ≤104\leq 10^4

  • 0≤row1i≤row2i<0 \leq \text{row1}_i \leq \text{row2}_i < n

  • 0≤col1i≤col2i<0 \leq \text{col1}_i \leq \text{col2}_i < n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Increment Submatrices by One

Try to solve the Increment Submatrices by One problem.

Statement

You are given a positive integer n, representing an n×nn \times n 00-indexed integer matrix mat initialized with all 00s.

You are also given a 22D integer array queries, where queries[i] =[row1i,col1i,row2i,col2i]= [\text{row1}_i, \text{col1}_i, \text{row2}_i, \text{col2}_i]. For each query, you must increment every cell mat[r][c] by 11 for all r and c such that row1i≤r≤row2i\text{row1}_i \leq r \leq \text{row2}_i and col1i≤c≤col2i\text{col1}_i \leq c \leq \text{col2}_i.

Return the matrix mat after processing all the queries.

Constraints:

  • 1≤1 \leq n ≤500\leq 500

  • 1≤1 \leq queries.length ≤104\leq 10^4

  • 0≤row1i≤row2i<0 \leq \text{row1}_i \leq \text{row2}_i < n

  • 0≤col1i≤col2i<0 \leq \text{col1}_i \leq \text{col2}_i < n