Binary Table
InterviewTime limit6sMemory limit1024 MB
Given a binary table and rectangle flips, report after each flip the fewest top-left rectangle flips needed to reset the table to all zeros.
- Level
Medium6 of 10
- Topics
- Matrix, Prefix sum
- Solved
- No attempts yet
Statement
You are given a table with rows and columns. Each cell holds a 0 or a 1. Rows are numbered from top to bottom, and columns are numbered from left to right. The cell in row and column has coordinates . The figure below also shows this.
The table supports a flip operation on a rectangle. Each operation is given by four numbers . The rectangle has opposite corners at and . Every cell inside it changes from 0 to 1 or from 1 to 0.
An operation is called simple if its top left corner is the top left corner of the table, that is, .
Initially every number in the table is 0. Then operations are applied, each changing the table. After each operation, find how many more simple operations would be needed to turn every number in the table back to 0.
Input
The first line contains three integers , , and (, ), the table size and the number of operations.
Each of the next lines describes one operation with four integers , , , (, ).
Output
Print exactly lines. The -th line contains the minimum number of simple operations needed to turn every number in the table to 0, after the first operations from the input have been applied.
Hint
The top row of the figure shows the table after the three operations from the input, applied in order. Each column shows the table being reset to zeros with the minimum number of simple operations.
