C++||clean/concise/easy to read and understand
Intuition\n Describe your first thoughts on how to solve this problem. \nApproach is simple we calculate the contribution of row or col according to last query 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nApproach is simple we calculate the contribution of row or col according to last query which have most priority , So we start from last and as we add contribution of any row and col we mark it as visited \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\nclass Solution {\npublic:\n   \n    long long matrixSumQueries(int n, vector<vector<int>>& q) {\n\n        long long ans=0;       \n       vector<int>row(n,0),col(n,0);   //making visited array for row and column\n        \n    int cntr=0,cntc=0;                 ///storing the count of num of row and col \n        for(int i=q.size()-1;i>=0;i--){     //taking last querie which have more priority \n             int ind=q[i][1];               //finding index of row or col\n             int val=q[i][2];\n                                             \n            if(q[i][0]==0){               //if type ==0 it\'s mean it is row\n               \n              if(row[ind]==0){\n                  ans+=val*(n-cntc);       //  adding contribution of (n-cntc ) row cell which will have value ==val\n                  row[ind]=1;               //mark visited\n                  cntr++;                 \n\n              }\n               \n            }\n            else {                             //if type ==1 it\'s mean it is col\n                \n             if(col[ind]==0){\n                ans+=val*(n-cntr);               //  adding contribution of (n-cntr ) col cell which will have value ==val\n                cntc++;\n                col[ind]=1;            //mark visited\n                }\n            \n            }\n            if(cntc+cntr==2*n) return ans;    //if all row and col visited then return ans\n        }\n               \n        return ans;\n    }\n};\n\n# please upvote \n\n\n\n\n\n
['Matrix']