Description
There is a matrix
M
that has
n
rows and
m
columns
.Then we perform
operations:
1 x y: Swap row x and row y ;
2 x y: Swap column x and column y ;
3 x y: Add y to all elements in row x ;
4 x y: Add y to all elements in column x ;
1 x y: Swap row x and row y ;
2 x y: Swap column x and column y ;
3 x y: Add y to all elements in row x ;
4 x y: Add y to all elements in column x ;
Input
There are multiple test cases. The first line of input contains an integer
indicating the number of test cases. For each test case:
The first line contains three integers , and .
The following lines describe the matrix M. for all .
The following lines contains three integers , and .
The first line contains three integers , and .
The following lines describe the matrix M. for all .
The following lines contains three integers , and .
Output
For each test case, output the matrix
after all
operations.
Sample Input
2 3 4 2 1 2 3 4 2 3 4 5 3 4 5 6 1 1 2 3 1 10 2 2 2 1 10 10 1 1 1 2 2 1 2
Sample Output
12 13 14 15
1 2 3 4
3 4 5 6
1 10
10 1
Hint
#include<stdio.h>//想了好半天,还是百度了,发现自己理解有问题,读错题意了... -.- #include<string.h> #include<iostream> #include<algorithm> using namespace std; typedef long long LL; const int maxn = 1000+10; int M[maxn][maxn],l[maxn],h[maxn],r[maxn],c[maxn]; int n,m,t,q; int main(){ scanf("%d",&t); while(t--){ scanf("%d%d%d",&m,&n,&q); for(int i=1; i<=m; i++){ h[i] = i; } for(int i=1; i<=n; i++){ l[i] = i; } for(int i=1; i<=m; i++){ for(int j=1; j<=n; j++){ scanf("%d",&M[i][j]); } } memset(r,0,sizeof(r)); memset(c,0,sizeof(c)); while(q--){ int a,x,y; long long ans = 0; scanf("%d%d%d",&a,&x,&y); if(a == 1){ swap(h[x],h[y]); } if(a == 2){ swap(l[x],l[y]); } if(a == 3){ r[h[x]] += y; } if(a == 4){ c[l[x]] += y; } } for(int i=1; i<=m; i++){ for(int j=1; j<n; j++){ printf("%d ",M[h[i]][l[j]] + r[h[i]] + c[l[j]]); } printf("%d\n",M[h[i]][l[n]] + r[h[i]] + c[l[n]]); } } return 0; }