F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Block Breaker

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 817    Accepted Submission(s): 456


Problem Description
Given a rectangle frame of size $n\times m$. Initially, the frame is strewn with $n\times m$ square blocks of size $1\times 1$. Due to the friction with the frame and each other, the blocks are stable and will not drop.

However, the blocks can be knocked down. When a block is knocked down, other remaining blocks may also drop since the friction provided by other remaining blocks may not sustain them anymore. Formally, a block will drop if it is knocked or not stable, which means that at least one of the left block and the right block has been dropped and at least one of the front block and the back block has been dropped. Especially, the frame can be regarded as a huge stable block, which means that if one block's left is the frame, only when its right block has been dropped and at least one of the front block and the back block has been dropped can it drop. The rest situations are similar.

Now you, the block breaker, want to knock down the blocks. Formally, you will do it $q$ times. In each time, you may choose a position $(x_i, y_i)$. If there remains a block at the chosen position, you will knock it down; otherwise, nothing will happen. Moreover, after knocking down the block, you will wait until no unstable blocks are going to drop and then do the next operation.

For example, please look at the following illustration, the frame is of size $2\times 2$ and the block $(1,1)$ and $(1,2)$ have been dropped. If we are going to knock the block $(2,2)$, not only itself but also the block $(2,1)$ will drop in this knocking operation.



You want to know how many blocks will drop in total in each knocking operation. Specifically, if nothing happens in one operation, the answer should be regarded as $0$.
 

Input
The first line contains one positive integer $T~(1\le T \le 10)$, denoting the number of test cases.

For each test case:

The first line contains three positive integers $n,m$ and $q~(1\le n,m\le 2\,000, 1\le q\le 100\,000)$, denoting the sizes in two dimensions of the frame and the number of knocking operations.

Each of the following $q$ lines contains two positive integers $x_i$ and $y_i~(1\le x_i\le n, 1\le y_i \le m)$, describing a knocking operation.
 

Output
For each test case, output $q$ lines, each of which contains a non-negative integer, denoting the number of dropped blocks in the corresponding knocking operation.
 

Sample Input
2 2 2 3 1 1 1 2 2 2 4 4 6 1 1 1 2 2 1 2 2 4 4 3 3
 

Sample Output
1 1 2 1 1 2 0 1 11
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 00:26:13, Gzip enabled