#P11053. [IOI 2024] 马赛克上色
[IOI 2024] 马赛克上色
Background
Do not include mosaic.h when submitting.
Do not use C++14 (GCC 9) for submission.
Problem Description
Salma wants to color a clay mosaic on a wall. The mosaic consists of square tiles, for a total of tiles. Each tile has size and is initially uncolored. 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 . Each tile is colored either white (denoted ) or black (denoted ).
To color the mosaic, Salma first chooses two arrays and of length , each consisting of and , and with . She colors the top row (row ) according to array , so that tile has color (). She colors the leftmost column (column ) according to array , so that tile has color ().
Then she repeats the following steps until all tiles are colored:
- She finds any uncolored tile such that the tile directly above it and the tile directly to its left are both already colored.
- Then, if both of these adjacent tiles are white, she colors tile black; otherwise, she colors it white.
It can be proven that the final colors of the tiles do not depend on the order in which Salma colors them.
Yasmin is very curious about the colors of the mosaic tiles. She asks Salma questions, numbered from to . In question (), Yasmin specifies a rectangle in the mosaic using the following information:
- The top row and the bottom row ().
- The left column and the right column ().
The answer to a question is the number of black tiles inside that rectangle. More precisely, Salma should determine how many tiles satisfy , , and are colored black.
Write a program to answer Yasmin’s questions.
Implementation Details
You need to implement the following function.
std::vector<long long> mosaic(
std::vector<int> X, std::vector<int> Y,
std::vector<int> T, std::vector<int> B,
std::vector<int> L, std::vector<int> R)
- , : arrays of length , describing the colors of the top row and the leftmost column, respectively.
- , , , : arrays of length , describing Yasmin’s questions.
- The function should return an array of length , where gives the answer to question ().
- For each test case, this function is called exactly once.
Input Format
The sample grader reads input in the following format:
N
X[0] X[1] ... X[N-1]
Y[0] Y[1] ... Y[N-1]
Q
T[0] B[0] L[0] R[0]
T[1] B[1] L[1] R[1]
...
T[Q-1] B[Q-1] L[Q-1] R[Q-1]
Output Format
The sample grader prints your answers in the following format:
C[0]
C[1]
...
C[S-1]
Here, is the length of the array returned by mosaic.
4
1 0 1 0
1 1 0 1
2
0 3 0 3
2 3 0 2
7
3
Hint
Consider the following function call.
mosaic([1, 0, 1, 0], [1, 1, 0, 1], [0, 2], [3, 3], [0, 0], [3, 2])
This example is shown in the figure below. The figure on the left shows the colors of the tiles in the mosaic. The middle and right figures show the rectangles in Yasmin’s first and second questions, respectively.

The answers to the two questions (that is, the number of in the shaded rectangles) are and , respectively. Therefore, the function should return .
Constraints
- For all with , and .
- .
- For all with , and .
| Subtask | Score | Additional Constraints |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | For all with , | |
| 4 | ||
| 5 | For all with , | |
| 6 | For all with , and | |
| 7 | For all with , | |
| 8 | No additional constraints. |
Translated by ChatGPT 5