← 返回 meta 的题目列表In-place Copy of Regions in a Matrix
类型:online_judge
Given a 2D matrix, you are tasked with defining two identically-sized rectangular regions within this matrix. These two regions may overlap partially. Your task is to copy the contents of one region to the other region in-place without using any extra memory. Implement this functionality and describe the operation process. Assume the matrix values are integers, and all the values fit within a 32-bit integer.
Input Format:
The first line contains two integers, m and n (1 ≤ m, n ≤ 1000), representing the matrix's dimensions.
The next m lines each contain n integers representing the matrix elements.
Line m+1 contains four integers r1, c1, r2, c2 (0 ≤ r1, r2 < m, 0 ≤ c1, c2 < n), denoting the top-left and bottom-right corners of the first rectangular region.
Line m+2 contains four integers r3, c3, r4, c4 (0 ≤ r3, r4 < m, 0 ≤ c3, c4 < n), denoting the top-left and bottom-right corners of the second rectangular region.
Output Format:
Print the modified matrix to standard output.
Sample Input:
5 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
0 0 1 1
2 2 3 3
Sample Output:
1 2 3 4 5
1 2 8 9 10
11 12 13 14 15
11 12 18 19 20
21 22 23 24 25
Example
Input
5 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
0 0 1 1
2 2 3 3