CodeForces 668A Little Artem and Matrix
4384 단어 모방하다
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to mfrom left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
output
8 2
1 8
input
3 3 2
1 2
3 2 2 5
output
0 0 0
0 0 5
0 0 0
토로하자면, 제목이 정말 길어서 이해하기 어렵다...
제목: n*m 행렬 조작
조작1: r행의 마지막 원소를 첫 번째, 두 번째를 세 번째에 놓고 순서대로 뒤로 밀어낸다.
조작2: c열의 마지막 요소를 첫 번째, 두 번째를 세 번째, 순서대로 뒤로 옮긴다.
작업 3: r행 c열의 요소에 X 값을 지정합니다.
사고방식: 조작에 따라 한 번 진행하지만 값을 부여하는 조작을 하고 다시 전환해야 한다.
#include
#include
#include
using namespace std;
struct note
{
int temp;
int r,c,val;
}t[110000];
int map[1100][1100];
int main()
{
int n,m,p,a,i,j;
while(scanf("%d%d%d",&n,&m,&p)!=EOF)
{
memset(map,0,sizeof(map));
for(i=1;i<=p;i++)
{
scanf("%d",&a);
t[i].temp=a;
if(a==1)
{
scanf("%d",&t[i].r);
}
if(a==2)
{
scanf("%d",&t[i].c);
}
if(a==3)
{
scanf("%d%d%d",&t[i].r,&t[i].c,&t[i].val);
}
}
for(i=p;i>=1;i--)
{
if(t[i].temp==3)
map[t[i].r][t[i].c]=t[i].val;
if(t[i].temp==2)
{
int ans=map[n][t[i].c];
for(j=n-1;j>=1;j--)
map[j+1][t[i].c]=map[j][t[i].c];
map[1][t[i].c]=ans;
}
if(t[i].temp==1)
{
int ans=map[t[i].r][m];
for(j=m-1;j>=1;j--)
map[t[i].r][j+1]=map[t[i].r][j];
map[t[i].r][1]=ans;
}
}
for(i=1;i<=n;i++)
{
for(j=1;j