#P4898. Beautiful Rectangle Seating

    ID: 18139 Type: Default 1000ms 256MiB

Beautiful Rectangle Seating

Beautiful Rectangle Seating

You are organizing an international programming contest in a rectangular hall that has H rows and W columns, for a total of HW seats. The rows are numbered from 0 to H-1 and the columns from 0 to W-1. The seat in row r and column c is denoted by (r, c).

You have invited exactly HW contestants, numbered from 0 to HW-1. You prepared a seating assignment so that the i-th contestant (for 0 \le i \le HW - 1) is assigned to seat (R_i, C_i). This assignment is a one‐to‐one correspondence between contestants and seats.

A set of seats S in the hall is called a rectangle if there exist integers r1, r2, c1, c2 satisfying \[ 0 \le r_{1} \le r_{2} \le H - 1, \quad 0 \le c_{1} \le c_{2} \le W - 1, \] such that S is exactly the set of seats \[ \{(r, c) \mid r_{1} \le r \le r_{2} \text{ and } c_{1} \le c \le c_{2}\}. \]

A rectangular set of seats containing k (1 \le k \le HW) seats is called beautiful if the set of contestant numbers assigned to those seats is exactly \{0, 1, \dots, k-1\}.

The beauty of a seating assignment is defined as the number of beautiful rectangular seat sets.

After the seating chart is prepared, you will receive Q swap requests, numbered from 0 to Q-1. The j-th request asks you to swap the seats of contestants A_j and B_j. After processing each request immediately (i.e. updating the seating assignment), your task is to compute and output the current beauty.

inputFormat

The first line contains three integers H, W and Q.

The next HW lines each contain two integers R and C. The i-th of these lines (for 0 \le i \le HW-1) indicates that contestant i is initially assigned to seat (R, C).

Each of the following Q lines contains two integers A and B describing a swap request: swap the seats of contestants A and B.

outputFormat

Output Q lines. The j-th line should contain the beauty of the current seating assignment after processing the j-th swap request.

sample

2 2 1
0 0
0 1
1 0
1 1
1 2
4

</p>