C++ Simple Solution
Intuition\nWhen we make a column change then all row would get affected similarly if we make a row change then all columns would be affected.\nNow keeping this 
# Intuition\nWhen we make a column change then all row would get affected similarly if we make a row change then all columns would be affected.\nNow keeping this in mind we now just have to think how many row or columns are affected and that can be done by storing number of column change and row change in a variable (Here r and c).\nThen we can easily subtract that amount from our answer.\n\n# Code\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        int d[n][2];\n        long long ans=0;\n        for(int i=0;i<n;i++){\n            d[i][0]=1;\n            d[i][1]=1;\n        }\n        int r=0,c=0;\n        int q=queries.size();\n        for(int i=q-1;i>=0;i--){\n            if(d[queries[i][1]][queries[i][0]]){\n            if(queries[i][0]) c++;\n            else r++;\n            ans+=(n-(queries[i][0]==0? c:r))*queries[i][2];\n            d[queries[i][1]][queries[i][0]]=0;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']