100% || C++
IntuitionSee from last to first bcz what is at first will be overwritten by last.
We maintain a set to keep record of visited row/column
rowrem and colrem denot
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

See from last to first bcz what is at first will be overwritten by last.
We maintain a set to keep record of visited row/column 
rowrem and colrem denote the row/col which is not processed yet

# Code
```cpp []
class Solution {
public:
    long long matrixSumQueries(int n, vector<vector<int>>& q) {
        // reverse(queries.begin(),queries.end());

        unordered_set <int> row;
        unordered_set <int> col;

        int rowrem=n;
        int colrem=n;

        long long ans=0;

        for(int i=q.size()-1;i>=0;i--){
            int type=q[i][0];
            int index=q[i][1];
            int val=q[i][2];
            
            if(type==0 && !row.count(index)){
                row.insert(index);
                ans+=colrem*val;
                rowrem--;
            }

            else if(type==1 && !col.count(index)){
                col.insert(index);
                ans+=rowrem*val;
                colrem--;
            }
        }
        return ans;
    }
};
```
['C++']