CF641B.Little Artem and Matrix
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 m from 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.
小 Artem 喜欢电子学。他可以花大量时间设计各种电路图,并在附近的电子商店里寻找新奇的元件。最近,商店进了一批新型控制元件,Artem 立刻买下了一个。
该元件能够存储一个大小为 n×m 的整数矩阵。该元件共有 n+m 个输入端口,即每一行和每一列都对应一个输入端口。当某个行对应的输入端口接收到信号时,该行将向左循环移位:行中第一个元素变为最后一个元素,第二个元素变为第一个元素,依此类推。当某个列对应的输入端口接收到信号时,该列将向上循环移位:列中第一个元素变为最后一个元素,第二个元素变为第一个元素,依此类推。行编号从上到下依次为 1 至 n,列编号从左到右依次为 1 至 m。
Artem 希望在实际使用前对该元件进行细致研究。为此,他计划开展一个包含 q 轮操作的实验。每轮操作中,他要么向某个输入端口发送信号,要么查询矩阵中某位置上当前存储的数值。
Artem 已完成实验并记录下了所有结果,但芯片却丢失了!请帮助 Artem 找出任意一个初始矩阵,使其能完全匹配实验所记录的结果。题目保证实验数据是一致的,即至少存在一个合法的初始矩阵。
输入格式
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 t__i (1 ≤ t__i ≤ 3) that defines the type of the operation. For the operation of first and second type integer r__i (1 ≤ r__i ≤ n) or c__i (1 ≤ c__i ≤ m) follows, while for the operations of the third type three integers r__i, c__i and x__i (1 ≤ r__i ≤ n, 1 ≤ c__i ≤ m, - 109 ≤ x__i ≤ 109) are given.
Operation of the first type (t__i = 1) means that signal comes to the input corresponding to row r__i, that is it will shift cyclically. Operation of the second type (t__i = 2) means that column c__i will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row r__i and column c__i stores value x__i.
输入的第一行包含三个整数 n、m 和 q(1 ≤ n, m ≤ 100,1 ≤ q ≤ 10000),分别表示矩阵的行数、列数以及实验中的操作次数。
接下来的 q 行每行描述一次操作。每行操作描述以一个整数 ti(1 ≤ ti ≤ 3)开头,用于指定操作类型。对于第一类和第二类操作,其后分别跟一个整数 ri(1 ≤ ri ≤ n)或 ci(1 ≤ ci ≤ m);而对于第三类操作,则其后跟三个整数 ri、ci 和 xi(1 ≤ ri ≤ n,1 ≤ ci ≤ m,−109 ≤ xi ≤ 109)。
第一类操作(ti=1)表示信号到达对应第 ri 行的输入端口,即该行将进行循环移位。
第二类操作(ti=2)表示第 ci 列将进行循环移位。
第三类操作表示在当前时刻,位于第 ri 行、第 ci 列的单元格中存储的值为 xi。
输出格式
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.
输出任意一个合法的初始矩阵的描述,即输出 n 行,每行包含 m 个整数。所有输出的整数的绝对值均不应超过 109。
若存在多个合法解,输出其中任意一个即可。
输入输出样例
输入#1
2 2 6 2 1 2 2 3 1 1 1 3 2 2 2 3 1 2 8 3 2 1 8
输出#1
8 2 1 8
输入#2
3 3 2 1 2 3 2 2 5
输出#2
0 0 0 0 0 5 0 0 0
输入解题思路,AI测评打分。不知道怎么写?