Canadian Computing Olympiad: 2017 Day 1, Problem 3
After being inspired by the great painter Picowso, Vera decided to make her own masterpiece. She has an empty painting surface which can be modeled as an infinite 2D coordinate plane. Vera likes powers of two and will paint some points in a repeated manner using step sizes which are a power of two.
Vera will paint times. The -th time can be described by three integers , , . Let be the largest power of two not greater than and let be the largest power of two not greater than .
Vera will add a paint drop with colour to all points that are of the form , where , are non-negative integers. A point may have multiple paint drops on it or have multiple drops of the same colour.
Then Vera will ask questions. For the -th question she wants to know the colour at the point . The colour at a point is equal to the sum of the colours of all paint drops at that point. If there are no paint drops at a point, the colour of that point is .
Since you are forced to be her art assistant, you will have to answer Vera's questions.
The first line contains two integers , , separated by one space .
The next lines each contain three space-separated integers, , , representing the paint drops of colour .
The next lines each contain two space-separated integers , representing the questions about the point .
For 5 of the 25 available marks, .
For an additional 5 of the 25 available marks, .
For an additional 5 of the 25 available marks, and .
The output will be lines. The -th line should have one integer, which is the colour of 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
Explanation for Sample Output
Let colour , , , , be red, blue, green, orange, purple respectively.
Let , be non-negative integers, then:
- Points have a red paint drop.
- Points have a blue paint drop.
- Points have a green paint drop.
- Points have a orange paint drop.
- Points have a purple paint drop.
The painting from to is shown below:
We can see that:
- has a red paint drop, so it has colour .
- has a red, blue and purple paint drop, so it has colour .
- has no paint drops, so it has colour .
- has a red and purple paint drop, so it has colour .
- has a orange paint drop, so it has colour .
- has a green paint drop, so it has colour .