C++ || O(n) Reverse Iteration
We reverse the queries given bcoz in reverse manner what we place in the matrix will cannot be changed by any other operations. \nlet if the operation is on row
We reverse the queries given bcoz in reverse manner what we place in the matrix will cannot be changed by any other operations. \nlet if the operation is on row then we set that row to zero and increment the col bcoz when we perform operation in row then one col is occupied and same for cols.\nEdge Case: if cols[i] or rows[i] is already zero then we dont have to decrement the srow or scol as there is no new col or row is changed\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        vector<int>rows(n,n),cols(n,n);\n        reverse(queries.begin(),queries.end());\n        long long sum=0,scol=0,srow=0;\n        for(int i=0;i<queries.size();i++)\n        {\n            long long type=queries[i][0],indx=queries[i][1],val=queries[i][2];\n            if(type)\n            {\n                sum+=max(cols[indx]-scol,0ll)*(long long)val;\n                if(srow<n&&cols[indx]!=0)\n\t\t\t\t\tsrow++;\n                cols[indx]=0;\n            }\n            else \n            {\n                sum+=max(rows[indx]-srow,0ll)*(long long)val;\n                if(scol<n&&rows[indx]!=0)\n\t\t\t\t\tscol++;  \n                rows[indx]=0;\n            }\n        }\n        return sum;\n    }\n};``\n```
['C']