size × size grid, initially all zeros. You get a list of paint operations paints, each a triple [kind, index, value]:
- if kind == 0, every cell of row index is set to value;
- if kind == 1, every cell of column index is set to value.
Operations are applied in order, later ones overwrite earlier ones. Return the sum of all numbers in the grid after the last operation.
The grid can be huge, so do not build it.size=2, paints=[[0, 0, 5], [1, 1, 2]] → 9
First the top row becomes [5, 5], then the right column is repainted to 2: the grid is [[5, 2], [0, 2]], sum 9.
size=3, paints=[[1, 0, 4], [1, 0, 1], [0, 2, 3]] → 11
The left column is painted 4, then 1. Then the bottom row gets 3, including its left cell. Sum: 1 + 1 + 3 + 3 + 3 = 11.
kind is 0 or 1size=2, paints=[[0, 0, 5], [1, 1, 2]]
9
Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.