Alchemy
Time limit2sMemory limit1024 MB
After each rod is painted, the task counts unit squares of an n by m grid with exactly t painted sides, for every t from 0 to 4.
- Level
Medium6 of 10
- Topics
- Math, Sorting, Implementation
- Solved
- No attempts yet
Problem
For many years, alchemists tried to perform transmutation with the Philosopher's Stone. The alchemist Vlachur came very close. Vlachur has a rectangular metal grid made of iron rods, sized by . The horizontal rods are numbered from to from bottom to top, and the vertical rods are numbered from to from left to right.
To carry out the transmutation, Vlachur performs the following operation: he takes one rod and paints all of it with magic paint. To see how close he is to his goal, he needs to know how many unit-area squares of his grid have exactly () painted sides. Help him!
Input
The first line contains three integers , , and (, ), the grid size and the number of operations. Each of the next lines describes an operation.
If the first character of the line is h, the same line contains an integer (), and the operation paints horizontal rod . Similarly, a line starting with v followed by an integer () paints vertical rod .
A line consisting of a single ? means you must output five numbers: for every from to , print , the number of sub-rectangles of the grid that have exactly painted sides.
Output
For each ? operation, print five numbers: the required counts .