## Sum of Matrix After Queries solution leetcode

You are given an integer `n`

and a **0-indexed** **2D array** `queries`

where `queries[i] = [type`

._{i}, index_{i}, val_{i}]

Initially, there is a **0-indexed** `n x n`

matrix filled with `0`

‘s. For each query, you must apply one of the following changes:

- if
`type`

, set the values in the row with_{i}== 0`index`

to_{i}`val`

, overwriting any previous values._{i} - if
`type`

, set the values in the column with_{i}== 1`index`

to_{i}`val`

, overwriting any previous values._{i}

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:23Explanation: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:17Explanation:The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 17.

## Sum of Matrix After Queries solution leetcode

**Constraints:**

`1 <= n <= 10`

^{4}`1 <= queries.length <= 5 * 10`

^{4}`queries[i].length == 3`

`0 <= type`

_{i}<= 1`0 <= index`

_{i}< n`0 <= val`

_{i}<= 10^{5}