#P6344. [CCO 2017] Vera 与现代艺术
[CCO 2017] Vera 与现代艺术
Description
Inspired by the great painter Picasso, Vera decided to create her masterpiece. She has a canvas that can be simplified as an infinitely large 2D plane. Vera likes integer powers of , and she will color some points using step sizes that are powers of .
Vera will color times. The -th coloring operation is described by three integers . Let be the largest power of that is not greater than , and let be the largest power of that is not greater than . Vera will use color to color all points with coordinates , where are non-negative integers. A point may be colored multiple times with different colors, and it may also be colored multiple times with the same color. The color value of a point is the sum of all colors that have been applied to that point.
Then Vera will ask questions. For the -th question, she wants to know the color value of the point at coordinates . If a point has never been colored, then its color value is .
Because you are forced to be Vera's assistant, you have to answer Vera's questions.
Input Format
The first line contains two integers , separated by a space.
The next lines each contain three integers separated by spaces, meaning that the coloring operation described in the statement is performed using color , with parameters and .
The next lines each contain two integers separated by spaces, asking for the color value of the point .
Output Format
Output lines. Each line contains one integer. The integer on the -th line is the color value of the point .
5 6
1 2 1
3 4 2
4 5 3
6 3 4
7 1 5
2 6
7 8
5 9
11 2
10 7
4 5
1
8
0
6
4
3
Hint
Sample Explanation
Let colors be red, blue, green, orange, and purple, respectively.
Let be non-negative integers. Then:
- Points with coordinates are colored red.
- Points with coordinates are colored blue.
- Points with coordinates are colored green.
- Points with coordinates are colored orange.
- Points with coordinates are colored purple.
The coordinate grid from to is shown in the figure:
We can observe that:
- is colored red, so its color value is .
- is colored red, blue, and purple, so its color value is .
- is not colored, so its color value is .
- is colored red and purple, so its color value is .
- is colored orange, so its color value is .
- is colored green, so its color value is .

Constraints and Notes
- For of the testdata, .
- For another of the testdata, .
- For another of the testdata, and .
- For of the testdata, , , , , and .
Due to issues with the judging machine, only the last test cases are kept.
Source: CCO 2017 Day 1 “ Vera and Modern Art ”.
Note: This translation is from LOJ.
Translated by ChatGPT 5
京公网安备 11011102002149号