java.lang.Object
g2701_2800.s2718_sum_of_matrix_after_queries.Solution

public class Solution extends Object
2718 - Sum of Matrix After Queries.<p>Medium</p> <p>You are given an integer <code>n</code> and a <strong>0-indexed</strong> <strong>2D array</strong> <code>queries</code> where <code>queries[i] = [type<sub>i</sub>, index<sub>i</sub>, val<sub>i</sub>]</code>.</p> <p>Initially, there is a <strong>0-indexed</strong> <code>n x n</code> matrix filled with <code>0</code>&rsquo;s. For each query, you must apply one of the following changes:</p> <ul> <li>if <code>type<sub>i</sub> == 0</code>, set the values in the row with <code>index<sub>i</sub></code> to <code>val<sub>i</sub></code>, overwriting any previous values.</li> <li>if <code>type<sub>i</sub> == 1</code>, set the values in the column with <code>index<sub>i</sub></code> to <code>val<sub>i</sub></code>, overwriting any previous values.</li> </ul> <p>Return <em>the sum of integers in the matrix after all queries are applied</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2023/05/11/exm1.png" alt="" /></p> <p><strong>Input:</strong> n = 3, queries = [[0,0,1],[1,2,2],[0,2,3],[1,0,4]]</p> <p><strong>Output:</strong> 23</p> <p><strong>Explanation:</strong> The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 23.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2023/05/11/exm2.png" alt="" /></p> <p><strong>Input:</strong> n = 3, queries = [[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]]</p> <p><strong>Output:</strong> 17</p> <p><strong>Explanation:</strong> The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 17.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 10<sup>4</sup></code></li> <li><code>1 <= queries.length <= 5 * 10<sup>4</sup></code></li> <li><code>queries[i].length == 3</code></li> <li><code>0 <= type<sub>i</sub> <= 1</code></li> <li><code>0 <= index<sub>i</sub> < n</code></li> <li><code>0 <= val<sub>i</sub> <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • matrixSumQueries

      public long matrixSumQueries(int n, int[][] queries)