Beats 100% of C++ Users || Solution using Simple Hash map|{}
IntuitionThe problem requires efficiently processing a series of queries on an n x n matrix. Instead of updating all n elements for each row and column modifica
# Intuition
The problem requires efficiently processing a series of queries on an n x n matrix. Instead of updating all n elements for each row and column modification, we use a reverse processing approach to track which rows and columns have already been modified. This prevents redundant operations and optimizes the computation.

The key observation is that the most recent query on a row or column determines its final value, so we process the queries in reverse order to apply only the first occurrence of each row and column update.

# Approach
**Use hash sets to track updates:**

    Maintain two sets: row to track updated rows and column to track updated columns.

    Track counts ro (rows updated) and col (columns updated).

**Process queries in reverse order:**

    If the query affects a row that hasn’t been updated yet, compute the contribution to the final sum and mark it as updated.

    If the query affects a column that hasn’t been updated yet, compute the contribution to the final sum and mark it as updated.

    Avoid redundant updates using hash sets.

**Update the sum efficiently:**

    If modifying a row, add vali * (n - col), where col accounts for the already modified columns.

    If modifying a column, add vali * (n - ro), where ro accounts for the already modified rows.

**Return the computed sum.**

# Complexity
- Time complexity:
**O(m)**, where m is the number of queries, since we process each query once.

- Space complexity:
**O(n)** to store row and column sets

# Code
```cpp []
class Solution {
public:
    long long matrixSumQueries(int n, vector<vector<int>>& q) {
        int m = q.size();
        long long ans = 0;
        unordered_set<int> row, column;
        int ro = 0;
        int col = 0;
        for (int i = m - 1; i >= 0; i--) {
            if (q[i][0] == 0) {
                if (row.find(q[i][1]) == row.end()) {
                    ans += q[i][2] * n - (col * q[i][2]);
                    ro++;
                    row.insert(q[i][1]);
                }
            } else {
                if (column.find(q[i][1]) == column.end()) {
                    ans += (q[i][2] * n) - (ro * q[i][2]);
                    col++;
                    column.insert(q[i][1]);
                }
            }
            cout << q[i][2] << " ";
        }
        return ans;
    }
};
```
['Array', 'Hash Table', 'C++']