Mosaic
문제
Salma plans to colour a clay mosaic on a wall. The mosaic is an grid, made of initially uncoloured square tiles. The rows of the mosaic are numbered from to from top to bottom, and the columns are numbered from to from left to right. The tile in row and column (0 ≤ i < N, 0 ≤ j < N) is denoted by . Each tile must be coloured either white (denoted by ) or black (denoted by ).
To colour the mosaic, Salma first picks two arrays and of length , each consisting of values and , such that . She colours the tiles of the topmost row (row ) according to array , such that the colour of tile is (0 ≤ j < N). She also colours the tiles of the leftmost column (column ) according to array , such that the colour of tile is (0 ≤ i < N).
Then she repeats the following steps until all tiles are coloured:
- She finds any uncoloured tile such that its up neighbor (tile ) and left neighbor (tile ) are both already coloured.
- Then, she colours tile black if both of these neighbors are white; otherwise, she colours tile white.
It can be shown that the final colours of the tiles do not depend on the order in which Salma is colouring them.
Yasmin is very curious about the colours of the tiles in the mosaic. She asks Salma questions, numbered from to . In question (0 ≤ k < Q), Yasmin specifies a subrectangle of the mosaic by its:
- Topmost row and bottommost row (0 ≤ T[k] ≤ B[k] < N),
- Leftmost column and rightmost column (0 ≤ L[k] ≤ R[k] < N).
The answer to the question is the number of black tiles in this subrectangle. Specifically, Salma should find how many tiles exist, such that T[k] ≤ i ≤ B[k], L[k] ≤ j ≤ R[k], and the colour of tile is black.
Write a program that answers Yasmin's questions.