Under construction

Still being built. Things may change

Bestin

Time limit2sMemory limit1024 MB

Summary
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 n×mn \times m kilometer grid rectangle divided into n⋅mn \cdot m 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 x⋅yx \cdot y 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 99 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 nn and mm (1≤n,m≤100 0001 \le n, m \le 100\,000), the size of the city. The second line contains one integer kk (1≤k≤100 0001 \le k \le 100\,000), the number of walls torn down during the city's history. Each of the next kk 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 nn, and the second value is less than mm.

Output

Print kk numbers, one per line. The ii-th number is the number of areas in the city after the first ii walls have been torn down.

Examples1

  1. Example 1

    Input
    4 4
    7
    0 0 0 1
    0 0 1 0
    1 0 1 1
    1 1 0 1
    3 3 2 3
    3 2 2 2
    2 2 2 3
    
    Expected output
    15
    13
    12
    13
    12
    11
    9