Painting
InterviewTime limit2sMemory limit1024 MB
After each flip on a checkerboard grid, report the fewest cells to recolor so that black cells form a top block and white cells form the rest.
- Level
Medium5 of 10
- Topics
- Segment tree, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Magni and Modi got bored while waiting for the battle with Kratos, so they decided to have some fun with coloring. The coloring is an rectangle split into unit squares. Rows are numbered from to , and columns are numbered from to . Denote by the cell at the intersection of row and column . Initially the rectangle has a checkerboard pattern: cell is white if is even, and black otherwise. Modi likes order. He calls the simplicity of a coloring the minimum number of cells that must be recolored (turning a black cell white and a white cell black) so that there is an integer where cell is black if and white otherwise. In other words, the simplicity is the minimum number of cells whose color must change so that a line parallel to the side of length can be drawn with every cell above it black and every cell below it white. Magni likes creativity more than order. From time to time he flips the color of one cell, turning black into white and white into black. After each flip, Modi wants to know the simplicity of the resulting coloring. Magni makes flips in total, and at the -th flip he flips cell . Since Magni acts very fast, Modi asked you to write a program that helps him.
Input
The first line contains two integers and , the dimensions of the coloring (, ). The second line contains a single integer , the number of flips Magni made (). Each of the next lines contains two integers and , the coordinates of the cell flipped by the -th action (, ).
Output
Print lines. For each action of Magni, print the simplicity of the coloring after that action.