[Python] Reverse the queries | O(q) Explained
Idea behind Reverse :\nif the cells udated by the query i then some or all cells may be overwrite by the i+1 th query and so on\n\n\tclass Solution:\n\t\t\t\tde
Idea behind Reverse :\nif the cells udated by the query i then some or all cells may be overwrite by the i+1 th query and so on\n\n\tclass Solution:\n\t\t\t\tdef matrixSumQueries(self, n: int, queries: List[List[int]]) -> int:\n\t\t\t\t\trows = [0]*n  # row[i] : is ith row already filled ?\n\t\t\t\t\tcols = [0]*n  # col[i] : is ith col already filled ?\n\t\t\t\t\tfillRows = 0\n\t\t\t\t\tfillCols = 0\n\n\t\t\t\t\tres = 0\n\t\t\t\t\tfor i in range(len(queries)-1,-1,-1):\n\t\t\t\t\t\ttyp,idx,val = queries[i]\n\t\t\t\t\t\tif typ == 0:\n\t\t\t\t\t\t\tif rows[idx] == 1:  # idx row already filled\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\tres += (n - fillCols)*val   # fillCols cells already filled in the row idx\n\t\t\t\t\t\t\trows[idx] = 1  # idx row is filled now\n\t\t\t\t\t\t\tfillRows += 1  # increase the fill rows count as idx row is filled now\n\t\t\t\t\t\telse:\n\t\t\t\t\t\t\tif cols[idx] == 1:  # idx col already filled\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\tres += (n - fillRows)*val   # fillRows cells already filled in the col idx\n\t\t\t\t\t\t\tcols[idx] = 1  # idx col is filled now\n\t\t\t\t\t\t\tfillCols += 1  # increase the fill cols count as idx col is filled now\n\t\t\t\t\treturn res\n
['Array']