Class Solution
- java.lang.Object
-
- g2701_2800.s2718_sum_of_matrix_after_queries.Solution
-
public class Solution extends Object
2718 - Sum of Matrix After Queries.Medium
You are given an integer
nand a 0-indexed 2D arrayquerieswherequeries[i] = [typei, indexi, vali].Initially, there is a 0-indexed
n x nmatrix filled with0’s. For each query, you must apply one of the following changes:- if
typei == 0, set the values in the row withindexitovali, overwriting any previous values. - if
typei == 1, set the values in the column withindexitovali, overwriting any previous values.
Return the sum of integers in the matrix after all queries are applied.
Example 1:

Input: n = 3, queries = [[0,0,1],[1,2,2],[0,2,3],[1,0,4]]
Output: 23
Explanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 23.
Example 2:

Input: n = 3, queries = [[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]]
Output: 17
Explanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 17.
Constraints:
1 <= n <= 1041 <= queries.length <= 5 * 104queries[i].length == 30 <= typei <= 10 <= indexi < n0 <= vali <= 105
- if
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longmatrixSumQueries(int n, int[][] queries)
-