| 比赛 |
2026.9.12 |
评测结果 |
AAAATTTTTT |
| 题目名称 |
彩色卡牌 |
最终得分 |
40 |
| 用户昵称 |
xuyuqing |
运行时间 |
30.371 s |
| 代码语言 |
C++ |
内存使用 |
5.84 MiB |
| 提交时间 |
2026-09-12 11:24:51 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
const int N = 514;
const int Color = 350234;
int r;
int c;
int q;
int num[N][N];
int color[N][N];
bool vis[N][N];
bool color_vis[Color];
int xc[4] = {1, -1, 0, 0};
int yc[4] = {0, 0, 1, -1};
int res;
int main () {
freopen ("card.in", "r", stdin);
freopen ("card.out", "w", stdout);
scanf ("%d%d%d", &r, &c, &q);
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
scanf ("%d", &(num[i][j]));
}
}
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
scanf ("%d", &(color[i][j]));
}
}
int opt, x, y, z;
for (int i = 1; i <= q; i++) {
scanf ("%d%d%d%d", &opt, &x, &y, &z);
if (opt == 1) {
color[x][y] = z;
}
else {
memset (vis, 0, sizeof (vis));
memset (color_vis, 0, sizeof (color_vis));
res = 0;
queue<pair<int, int>> q;
if (z >= num[x][y]) {
q.emplace(x, y);
vis[x][y] = true;
}
while (!q.empty()) {
int nowx = q.front().first;
int nowy = q.front().second;
q.pop();
if (!color_vis[color[nowx][nowy]]) {
color_vis[color[nowx][nowy]] = true;
res++;
}
for (int i = 0; i < 4; i++) {
int xx = nowx + xc[i];
int yy = nowy + yc[i];
if (xx < 1 || xx > r || yy < 1 || yy > c || vis[xx][yy] || num[xx][yy] > z) {
continue;
}
vis[xx][yy] = true;
q.emplace(xx, yy);
}
}
printf ("%d\n", res);
}
}
return 0;
}