/**
* author: Haunted_Cpp
**/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
bitset<50005> cnt;
const int dr[] = {+1, -1, +0, +0};
const int dc[] = {+0, +0, -1, +1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int r, c, q;
cin >> r >> c >> q;
vector<vector<int>> lvl(r, vector<int>(c));
vector<vector<int>> type(r, vector<int>(c));
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> lvl[i][j];
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> type[i][j];
}
}
while(q--) {
int task;
cin >> task;
if (task == 1) {
int linha, coluna, new_type;
cin >> coluna >> linha >> new_type;
--coluna;
--linha,
type[linha][coluna] = new_type;
} else {
cnt.reset();
int linha, coluna, max_lvl;
cin >> coluna >> linha >> max_lvl;
--coluna;
--linha;
vector<vector<bool>> vis(r, vector<bool>(c, false));
function<void(int, int)> dfs = [&](int linha, int coluna) {
vis[linha][coluna] = true;
cnt[type[linha][coluna]] = true;
for (int i = 0; i < 4; i++) {
if (linha + dr[i] < 0 || linha + dr[i] >= r || coluna + dc[i] < 0 || coluna + dc[i] >= c) continue;
if (lvl[linha + dr[i]][coluna + dc[i]] > max_lvl) continue;
if (vis[linha + dr[i]][coluna + dc[i]]) continue;
vis[linha + dr[i]][coluna + dc[i]];
dfs(linha + dr[i], coluna + dc[i]);
}
};
if (lvl[linha][coluna] <= max_lvl) dfs(linha, coluna);
cout << cnt.count() << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2636 ms |
7268 KB |
Output is correct |
2 |
Correct |
1051 ms |
6964 KB |
Output is correct |
3 |
Correct |
363 ms |
6964 KB |
Output is correct |
4 |
Correct |
379 ms |
6836 KB |
Output is correct |
5 |
Correct |
1038 ms |
6964 KB |
Output is correct |
6 |
Correct |
2564 ms |
7092 KB |
Output is correct |
7 |
Correct |
1010 ms |
6964 KB |
Output is correct |
8 |
Correct |
1026 ms |
6964 KB |
Output is correct |
9 |
Correct |
1010 ms |
7092 KB |
Output is correct |
10 |
Correct |
1108 ms |
7032 KB |
Output is correct |
11 |
Correct |
1020 ms |
6988 KB |
Output is correct |
12 |
Correct |
986 ms |
6964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
6332 KB |
Output is correct |
2 |
Correct |
19 ms |
5436 KB |
Output is correct |
3 |
Correct |
17 ms |
5692 KB |
Output is correct |
4 |
Correct |
26 ms |
8116 KB |
Output is correct |
5 |
Correct |
52 ms |
9260 KB |
Output is correct |
6 |
Correct |
58 ms |
10176 KB |
Output is correct |
7 |
Correct |
31 ms |
5248 KB |
Output is correct |
8 |
Correct |
25 ms |
4480 KB |
Output is correct |
9 |
Correct |
24 ms |
4480 KB |
Output is correct |
10 |
Correct |
25 ms |
4864 KB |
Output is correct |
11 |
Correct |
31 ms |
4608 KB |
Output is correct |
12 |
Correct |
28 ms |
4224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5086 ms |
7328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2636 ms |
7268 KB |
Output is correct |
2 |
Correct |
1051 ms |
6964 KB |
Output is correct |
3 |
Correct |
363 ms |
6964 KB |
Output is correct |
4 |
Correct |
379 ms |
6836 KB |
Output is correct |
5 |
Correct |
1038 ms |
6964 KB |
Output is correct |
6 |
Correct |
2564 ms |
7092 KB |
Output is correct |
7 |
Correct |
1010 ms |
6964 KB |
Output is correct |
8 |
Correct |
1026 ms |
6964 KB |
Output is correct |
9 |
Correct |
1010 ms |
7092 KB |
Output is correct |
10 |
Correct |
1108 ms |
7032 KB |
Output is correct |
11 |
Correct |
1020 ms |
6988 KB |
Output is correct |
12 |
Correct |
986 ms |
6964 KB |
Output is correct |
13 |
Execution timed out |
5077 ms |
7192 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2636 ms |
7268 KB |
Output is correct |
2 |
Correct |
1051 ms |
6964 KB |
Output is correct |
3 |
Correct |
363 ms |
6964 KB |
Output is correct |
4 |
Correct |
379 ms |
6836 KB |
Output is correct |
5 |
Correct |
1038 ms |
6964 KB |
Output is correct |
6 |
Correct |
2564 ms |
7092 KB |
Output is correct |
7 |
Correct |
1010 ms |
6964 KB |
Output is correct |
8 |
Correct |
1026 ms |
6964 KB |
Output is correct |
9 |
Correct |
1010 ms |
7092 KB |
Output is correct |
10 |
Correct |
1108 ms |
7032 KB |
Output is correct |
11 |
Correct |
1020 ms |
6988 KB |
Output is correct |
12 |
Correct |
986 ms |
6964 KB |
Output is correct |
13 |
Correct |
35 ms |
6332 KB |
Output is correct |
14 |
Correct |
19 ms |
5436 KB |
Output is correct |
15 |
Correct |
17 ms |
5692 KB |
Output is correct |
16 |
Correct |
26 ms |
8116 KB |
Output is correct |
17 |
Correct |
52 ms |
9260 KB |
Output is correct |
18 |
Correct |
58 ms |
10176 KB |
Output is correct |
19 |
Correct |
31 ms |
5248 KB |
Output is correct |
20 |
Correct |
25 ms |
4480 KB |
Output is correct |
21 |
Correct |
24 ms |
4480 KB |
Output is correct |
22 |
Correct |
25 ms |
4864 KB |
Output is correct |
23 |
Correct |
31 ms |
4608 KB |
Output is correct |
24 |
Correct |
28 ms |
4224 KB |
Output is correct |
25 |
Execution timed out |
5086 ms |
7328 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |