Impressionism
题意翻译
### 题目描述
Burenka 有两张图片 $ a $ 和 $ b$ ,它们的大小可以表示为 $ n \times m $ 的像素组合。每幅画的每个像素都有一个颜色——表示为一个从 $0 $ 到 $2 \times 10^5$ 的数字,并且在两幅画的每一行或每一列中都没有重复的颜色,除了颜色 $0 $ 。
Burenka 想把图片 $a$ 变成图片 $b$。为了实现她的目标,Burenka 可以执行 $2$ 操作之一:交换 $a$ 的任意两行或其任意两列。现在需要你来告诉 Burenka 该如何操作
行从上到下被编号为$ 1 $ 到 $ n $ ,列从左到右被编号为 $ 1 $ 到 $ m $。
### 输入格式
第一行包含两个整数 $ n $ 和 $ m $ ( $ 1 \leq n \cdot m \leq 2 \cdot 10^5 $ ) — 图片的大小。
接下来的 $ n $ 行的第 $i$ 行包含 $ m $ 个整数 $ a_{i, 1}, a_{i, 2}, \ldots, a_{i, m} $ ( $ 0 \leq a_{ i,j} \leq 2 \cdot 10^5 $ ) — 图片 $ a $ 第 $ i $ 行的颜色。保证在同一行或同一列中没有相同的颜色,除了颜色 $ 0 $ 。
再接下来 $ n $ 行的第 $i$ 行包含 $ m $ 整数 $ b_{i, 1}, b_{i, 2}, \ldots, b_{i, m} $ ( $ 0 \leq b_{ i,j} \leq 2 \cdot 10^5 $ ) — 图片 $ b $ 第 $ i $ 行的颜色。保证在同一行或同一列中没有相同的颜色,除了颜色 $ 0 $ 。
### 输出格式
如果不能实现,输出 `-1` ;\
否则输出解决方案中的操作数 $ k $ ( $ 0 \le k \le 2 \cdot 10^5 $ )。可以证明 $ k \le 2 \cdot 10^5 $。
在接下来的 $k$ 行中输出操作内容。首先输出操作的类型($ 1 $ - 交换行,$ 2 $ - 交换列),然后输出应用操作的行或列的位置。
请注意,你不必刻意减少操作次数。
题目描述
Burenka has two pictures $ a $ and $ b $ , which are tables of the same size $ n \times m $ . Each cell of each painting has a color — a number from $ 0 $ to $ 2 \cdot 10^5 $ , and there are no repeating colors in any row or column of each of the two paintings, except color $ 0 $ .
Burenka wants to get a picture $ b $ from the picture $ a $ . To achieve her goal, Burenka can perform one of $ 2 $ operations: swap any two rows of $ a $ or any two of its columns. Tell Burenka if she can fulfill what she wants, and if so, tell her the sequence of actions.
The rows are numbered from $ 1 $ to $ n $ from top to bottom, the columns are numbered from $ 1 $ to $ m $ from left to right.
输入输出格式
输入格式
The first line contains two integers $ n $ and $ m $ ( $ 1 \leq n \cdot m \leq 2 \cdot 10^5 $ ) — the sizes of the table.
The $ i $ -th of the next $ n $ lines contains $ m $ integers $ a_{i, 1}, a_{i, 2}, \ldots, a_{i, m} $ ( $ 0 \leq a_{i,j} \leq 2 \cdot 10^5 $ ) — the colors of the $ i $ -th row of picture $ a $ . It is guaranteed that there are no identical colors in the same row or column, except color $ 0 $ .
The $ i $ -th of the following $ n $ lines contains $ m $ integers $ b_{i, 1}, b_{i, 2}, \ldots, b_{i, m} $ ( $ 0 \leq b_{i,j} \leq 2 \cdot 10^5 $ ) — the colors of the $ i $ -th row of picture $ b $ . It is guaranteed that there are no identical colors in the same row or column, except color $ 0 $ .
输出格式
In the first line print the number $ -1 $ if it is impossible to achieve what Burenka wants, otherwise print the number of actions in your solution $ k $ ( $ 0 \le k \le 2 \cdot 10^5 $ ). It can be proved that if a solution exists, then there exists a solution where $ k \le 2 \cdot 10^5 $ .
In the next $ k $ lines print the operations. First print the type of the operation ( $ 1 $ — swap rows, $ 2 $ — columns), and then print the two indices of rows or columns to which the operation is applied.
Note that you don't have to minimize the number of operations.
输入输出样例
输入样例 #1
3 3
1 0 2
0 0 0
2 0 1
2 0 1
0 0 0
1 0 2
输出样例 #1
1
1 1 3
输入样例 #2
4 4
0 0 1 2
3 0 0 0
0 1 0 0
1 0 0 0
2 0 0 1
0 3 0 0
0 1 0 0
0 0 1 0
输出样例 #2
4
1 3 4
2 3 4
2 2 3
2 1 2
输入样例 #3
3 3
1 2 0
0 0 0
0 0 0
1 0 0
2 0 0
0 0 0
输出样例 #3
-1