Mosaic
시간 제한1초메모리 제한1024 MB
맨 윗줄과 왼쪽 열의 색이 주어지고 이웃 규칙으로 나머지 칸이 정해질 때, Q개의 부분 직사각형에 있는 검은 칸 수를 구한다.
문제
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 (, ) 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 (). She also colours the tiles of the leftmost column (column ) according to array , such that the colour of tile is ().
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 (), Yasmin specifies a subrectangle of the mosaic by its:
- Topmost row and bottommost row (),
- Leftmost column and rightmost column ().
The answer to the question is the number of black tiles in this subrectangle. Specifically, Salma should find how many tiles exist, such that , , and the colour of tile is black.
Write a program that answers Yasmin's questions.
제한
- and for each such that
- and for each such that
예제
이 문제는 공개된 예제가 없습니다.