Bestin
Time limit2sMemory limit1024 MB
After each torn-down wall, count the sub-rectangles that are sealed off by walls on the perimeter and open inside.
- Level
Hard8 of 10
- Topics
- Union-find, Hash map, Implementation
- Solved
- No attempts yet
Statement
Bestin is the capital of the planet Tatooine. It is known for its huge number of gangsters and smugglers, and for its tricky geography.
The city is an kilometer grid rectangle divided into blocks. Each block is one cell of this rectangle. When the city was founded, it was completely separated from the outside world by walls. In addition, every pair of adjacent blocks was separated by a wall.
Each block is identified uniquely by its coordinates. The first coordinate is the number of blocks between it and the city's north wall. The second coordinate is the number of blocks between it and the city's west wall. As the city grew, some walls between adjacent blocks were torn down.
In Bestin, an area is a sub-rectangle made of blocks. An area must satisfy these conditions:
- The area is separated from the rest of the city by walls along its entire perimeter.
- No two adjacent blocks inside the area are separated by a wall.

The figure shows the block coordinates. Dotted lines are torn-down walls, and solid lines are walls that remain. The city in the figure has exactly areas.
You are studying the history of Bestin's development. For each torn-down wall, find the number of areas in the city right after that wall was removed.
Input
The first line contains two integers and (), the size of the city. The second line contains one integer (), the number of walls torn down during the city's history. Each of the next lines describes one torn-down wall by giving two pairs of coordinates, the blocks on either side of the wall. Coordinates are non-negative integers. The first value of each block is less than , and the second value is less than .
Output
Print numbers, one per line. The -th number is the number of areas in the city after the first walls have been torn down.