You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 2050;
int blk[N][N];
inline bool unstable(int x, int y, int t)
{
return (blk[x - 1][y] == t || blk[x + 1][y] == t) && (blk[x][y - 1] == t || blk[x][y + 1] == t);
}
struct
{
int x, y;
} que[N * N];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
inline void read(int &x)
{
int ch = x = 0;
while (!isdigit(ch)) ch = getchar();
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
}
int Tt, T, n, m, q;
int dfs(int x, int y)
{
int ans = 1;
blk[x][y] = Tt;
for (int i = 0; i < 4; i++)
{
x += dx[i], y += dy[i];
if (x >= 1 && x <= n && y >= 1 && y <= m && blk[x][y] != Tt && unstable(x, y, Tt))
ans += dfs(x, y);
x -= dx[i], y -= dy[i];
}
return ans;
}
int main()
{
read(T);
for (int t = 1; t <= T; t++)
{
Tt = t;
read(n), read(m), read(q);
for (int x, y, len; q-- && (read(x), read(y), 1);)
if (blk[x][y] == t)
puts("0");
else
{
/*len = 0, que[len++] = {x, y};
for (int h = 0; h < len; h++)
{
auto cur = que[h];
blk[cur.x][cur.y] = t;
for (int i = 0; i < 4; i++)
{
cur.x += dx[i], cur.y += dy[i];
if (cur.x >= 1 && cur.x <= n && cur.y >= 1 && cur.y <= m && blk[cur.x][cur.y] != t && unstable(cur.x, cur.y, t))
que[len++] = cur;
cur.x -= dx[i], cur.y -= dy[i];
}
}*/
printf("%d\n", dfs(x, y));
}
}
return 0;
}