Submit | All submissions | Best solutions | Back to list |
PRINTMOVE2 - Move it, please! Part 2 |
After helping Lius, your best friend, he survived the trial from the company (see SPOJ PRINTMOVE for clarity). Now he has to deal with the real job. His boss now asked him to handle even more data. Lius was also given more commands than before. The commands available now are:
- "up" : Shift the data 1 row up, the data in top row is moved to the bottom row.
- "down" : Shift the data 1 row below, the data in bottom row is moved to the top row.
- "left" : Shift the data 1 columns to the left, the data in the first column is moved to the last column.
- "right" : Shift the data 1 columns to the right, the data in the last column is moved to the first column.
- "print x y": Print the value on the yth (1 ≤ y ≤ N) row and xth (1 ≤ x ≤ M) column.
- "modify x y a": Modify the value on the yth (1 ≤ y ≤ N) row and xth (1 ≤ x ≤ M) column with a(a will fit an 64-bit unsigned data type).
- "reset x y": Set the value on the yth row and xth column to 0.
Knowing that he is already incapable of handling the first task, he pleads you to help him create a program to help him finish his work. You would help him, wouldn't you?
Warning: large Input/Output data, be careful with certain languages!
Both input and output file of every testcase will not exceed 25MB
PS: For speed addict, my best solution is 2.11s for all test files
Input
First line of input consists of integer N and M (1 ≤ N,M ≤ 10^9), denoting the number of rows and columns of the matrix. The next line of input is an integer C (0 ≤ C ≤ 10^6), denoting the number of commands that should be done, followed by C lines, the orders that should be done by the program.
Output
For each time he is asked to print the value, print "Command #X: A", where X (1 ≤ X ≤ C) is the number of times he is asked to print the value, and A is the value that is asked by his boss. There must be no trailing spaces at the end of printed lines, neither empty characters. Print a newline after each command.
Example
Input: 3 3 10 print 2 2 up left print 1 1 modify 2 2 12345 down right print 3 3 reset 2 2 print 2 2 Output: Command #1: 5 Command #2: 5 Command #3: 12345 Command #4: 0
PS: The answer for the date and month in my problem GUESSBDAY is the date I created this problem :), which is also a week before the Independence Day of my country .
Added by: | hanstan |
Date: | 2016-08-10 |
Time limit: | 0.5s-1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU |
Resource: | Self |
hide comments