Easy sol^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:\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```\nbool compare(pair<int,int>a,pair<int,int>b)\n{\n   if(a.first>b.first)\n   return true;\n   else\n   return false;\n}\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n          int c=1;\n          vector<pair<int,int>>row(n,{-1,0});\n          vector<pair<int,int>>col(n,{-1,0});\n          for(int i=0;i<queries.size();i++)\n          {\n              if(queries[i][0]==0)\n              {\n                 row[queries[i][1]]={c,queries[i][2]};\n              }\n              else\n              {\n               col[queries[i][1]]={c,queries[i][2]};\n              }\n              c++;\n          }\n          sort(row.begin(),row.end(),compare);\n          sort(col.begin(),col.end(),compare);\n          int r1=0;\n          int c1=0;\n          int i=0;\n          int j=0;\n          long long sum=0;\n          while(i<row.size()&&j<col.size())\n          {\n              if(col[j].first<row[i].first)\n              {\n                   if(row[i].first==-1)\n                   i++;\n                   else\n                   {\n                      sum=sum+(long long)((n-r1)*row[i].second);\n                      c1++;\n                      i++;\n                   }\n              }\n              else\n              {\n                 if(col[j].first==-1)\n                 j++;\n                 else\n                   {\n                      sum=sum+(long long)((n-c1)*col[j].second);\n                      r1++;\n                      j++;\n                   }\n              }\n          }\n          while(i<row.size())\n          {\n             if(row[i].first==-1)\n                   i++;\n                   else\n                   {\n                      sum=sum+(long long)((n-r1)*row[i].second);\n                      i++;\n                   }\n          }\n          while(j<col.size())\n          {\n              if(col[j].first==-1)\n                 j++;\n                 else\n                   {\n                      sum=sum+(long long)((n-c1)*col[j].second);\n                      j++;\n                   }\n          }\n          return sum;\n    }\n};\n```
['Array', 'Sorting', 'C++']