Reverse your queries
IntuitionApproachComplexity

Time complexity:
O(queries length)


Space complexity:
O(queries length)

Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(queries length)

- Space complexity:
O(queries length)

# Code
```javascript []
/**
 * @param {number} n
 * @param {number[][]} queries
 * @return {number}
 */
var matrixSumQueries = function(n, queries) {
    let rows = new Set()
    let cols = new Set()
    let mult = []
    for(let i = queries.length - 1 ; i >= 0  ; i--){
        let [type, index, val] = queries[i]
        if(type === 0){
            if(rows.has(index)){
                continue
            }
            rows.add(index)
            mult.push([n-cols.size , val])
        }else{
            if(cols.has(index)){
                continue
            }
            cols.add(index)
            mult.push([n-rows.size , val])
        }
    }
    let res = 0
    for(let [m , v] of mult){
        res+=(m*v)
    }
    return res
};
```
['JavaScript']