PivotOJ

Mosaic

시간 제한: 1000ms메모리 제한: 1024MB출처: IOI 2024BOJ 32268

문제

Salma plans to colour a clay mosaic on a wall. The mosaic is an N×NN \times N grid, made of NN initially uncoloured 1×11 \times 1 square tiles. The rows of the mosaic are numbered from 00 to N1N - 1 from top to bottom, and the columns are numbered from 00 to N1N - 1 from left to right. The tile in row ii and column jj (0 &le; i < N, 0 &le; j < N) is denoted by (i,j)(i, j). Each tile must be coloured either white (denoted by 00) or black (denoted by 11).

To colour the mosaic, Salma first picks two arrays XX and YY of length NN, each consisting of values 00 and 11, such that X[0]=Y[0]X[0] = Y [0]. She colours the tiles of the topmost row (row 00) according to array XX, such that the colour of tile (0,j)(0, j) is X[j]X[j] (0 &le; j < N). She also colours the tiles of the leftmost column (column 00) according to array YY, such that the colour of tile (i,0)(i, 0) is Y[i]Y [i] (0 &le; i < N).

Then she repeats the following steps until all tiles are coloured:

  • She finds any uncoloured tile (i,j)(i, j) such that its up neighbor (tile (i1,j)(i - 1, j)) and left neighbor (tile (i,j1)(i, j - 1)) are both already coloured.
  • Then, she colours tile (i,j)(i, j) black if both of these neighbors are white; otherwise, she colours tile (i,j)(i, j) 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 QQ questions, numbered from 00 to Q1Q - 1. In question kk (0 &le; k < Q), Yasmin specifies a subrectangle of the mosaic by its:

  • Topmost row T[k]T[k] and bottommost row B[k]B[k] (0 &le; T[k] &le; B[k] < N),
  • Leftmost column L[k]L[k] and rightmost column R[k]R[k] (0 &le; L[k] &le; R[k] < N).

The answer to the question is the number of black tiles in this subrectangle. Specifically, Salma should find how many tiles (i,j)(i, j) exist, such that T[k] &le; i &le; B[k], L[k] &le; j &le; R[k], and the colour of tile (i,j)(i, j) is black.

Write a program that answers Yasmin's questions.

코드를 제출하려면 로그인하세요.