Simple and Easy to Understand || Time: O(n) || Space: O(n)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        int size = queries.size();\n        int rows = n, cols = n;\n        vector<bool> rowVis(n,0), colVis(n,0);\n        long ans = 0;\n        \n        //Iterating in reverse order so we don\'t have to update already visited rows/cols.\n        for(int i=size-1; i>=0; i--)\n        {\n            int type = queries[i][0];\n            int index = queries[i][1];\n            int val = queries[i][2];\n            \n            if(type == 0)\n            {\n              if(rowVis[index] == 0) //Checking whether the row is already visited.\n              {\n                rowVis[index] = 1;\n                ans += val*rows;\n                cols--; //No need to update already visited elements in next iterations.\n              }\n            }\n            else\n            {\n                if(colVis[index] == 0)\n                {\n                    colVis[index] = 1;\n                    ans += val*cols;\n                    rows--;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']