Shawn Coding
Intuition\nSimple Observation and start from last query and marked row and col as you traverse from last query. \nIf it Not marked then do following operation  
# Intuition\nSimple Observation and start from last query and marked row and col as you traverse from last query. \nIf it Not marked then do following operation  : \n\nif you fill the column then decrease column count but you have to add in your sum according to how many rows are left.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& q) {\n        long long sum = 0 ;\n        int m = q.size();\n        int row=n,col=n;\n        set<int>sr,sc;\n        for(int i = m-1;i>=0;i--){\n            int tp = q[i][0];\n            \n            if(tp==0){\n                //row operation\n                int r=q[i][1];\n                int val = q[i][2];\n\n                if(sr.find(r)==sr.end())\n                {\n                    sum = sum + col*val;\n                    row--;\n                    sr.insert(r);\n                }                \n            }\n            else{\n                int c = q[i][1];\n                int val=q[i][2];\n\n                if(sc.find(c)==sc.end()){\n                    sum = sum + row*val;\n                    col--;\n                    sc.insert(c);\n                }\n            }\n        }\n        return sum;\n    }\n};\n```
['C++']