2718. Sum of Matrix After Queries
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nnot an easy one\n\n# Complexity\n- Time complexity:\n Add your time compl
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nnot an easy one\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\n---\n\n```\nvar matrixSumQueries = function (n, qs) {\n  let sum = 0;\n\n  const rowsTaken = new Set();\n  const colsTaken = new Set();\n  let nROWSLeft = n;\n  let nColsLeft = n;\n\n  for (let i = qs.length - 1; i >= 0; i--) {\n\n    const [t, index, v] = qs[i];\n\n    if (t === 0) {\n      if (rowsTaken.has(index)) continue;\n      rowsTaken.add(index);\n\n      sum += v * nColsLeft;\n      nROWSLeft--;\n    } else {\n      if (colsTaken.has(index)) continue;\n      colsTaken.add(index);\n\n      sum += v * nROWSLeft;\n      nColsLeft--;\n    }\n  }\n  return sum;\n};\n```\n\n---\n
['JavaScript']