Short and Concise Erlang Solution
Approach\n Describe your approach to solving the problem. \nThe answer can be constructed in the reversed direction because of the fact that the previous update
# Approach\n<!-- Describe your approach to solving the problem. -->\nThe answer can be constructed in the reversed direction because of the fact that the previous update that will be repalced by a latter query does not matter. So, beginning from the last query, ignore seen rows/cols and sum up the values. \n\n\n# Complexity\n- Time complexity: $O(Q)$ where $Q$ is the number of queries. \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $O(n)$ where $n$ is the width (height) of the matrix. \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n-spec matrix_sum_queries(N :: integer(), Queries :: [[integer()]]) -> integer().\nmatrix_sum_queries(N, Queries) -> solve(lists:reverse(Queries), N, #{}, 0, #{}, 0).\n\nsolve([], N, Rows, RC, Cols, CC) -> 0;\nsolve(_, N, Rows, _, Cols, N) -> 0;\nsolve(_, N, Rows, N, Cols, _) -> 0;\nsolve([[0, Index, Val]|T], N, Rows, RC, Cols, CC) -> \n    case sets:is_element(Index, Rows) of\n        true -> solve(T, N, Rows, RC, Cols, CC);\n        false -> (N - CC) * Val + solve(T, N, sets:add_element(Index, Rows), RC + 1, Cols, CC)\n    end;\nsolve([[1, Index, Val]|T], N, Rows, RC, Cols, CC) -> \n    case sets:is_element(Index, Cols) of\n        true -> solve(T, N, Rows, RC, Cols, CC);\n        false -> (N - RC) * Val + solve(T, N, Rows, RC, sets:add_element(Index, Cols), CC + 1)\n    end.\n```
['Hash Table', 'Erlang']