10 int rows = mat.size();
11 int cols = mat[0].size();
12 vector<pair<int, int>> locations(rows * cols + 1);
13 vector<int> counts_x(rows, 0);
14 vector<int> counts_y(cols, 0);
17 for (
int i = 0; i < rows; ++i)
19 for (
int j = 0; j < cols; ++j)
21 locations[mat[i][j]] = {i, j};
26 for (
int i = 0; i < (int)arr.size(); ++i)
28 auto [x, y] = locations[arr[i]];
31 if (counts_x[x] == cols || counts_y[y] == rows)