## CCO '09 P5 - Parade

View as PDF

Points: 20 (partial)
Time limit: 0.6s
Memory limit: 128M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### Canadian Computing Competition: 2009 Stage 2, Day 2, Problem 2

May 9 is VE day, when the annual victory parade is held through Red Square. Inspired by the award ceremony of the 2009 ACM World Finals, you have decided to recreate the original VE day parade digitally. Since you have skillfully obtained all the necessary hardware, the most difficult part remaining is to track the configuration of a single formation.

A formation can be viewed as a 4-by-4 array, with the people initially labelled 1 through 16:

Then a sequence of commands are issued. Each command is a "rotation" based on the three integer parameters , and :

Rotate all people on the perimeter of a -by- square with its upper left corner located at row , column clockwise by one position.

For example, the command would alter the initial board to:

As another example, would bring the initial board to

A third example, would bring the initial board to

You have obtained the original sequence of commands issued. However, you are not quite pleased with the final result and would like to edit some of the commands. Support changes of the command sequence, each change as follows:

Change the th command to , and permanently.

Furthermore, you would like to see the effects of your change immediately. After each change, output what the formation would looks like at the end of all commands. To re-emphasize, each change is cumulative and permanent.

For of the test cases, .

#### Input Specification

The first line contains two integers and , which is the number of commands and number of edits, respectively.

The next lines contain three integers per line: , and which describe each rotation command. Note that , and .

The next lines contain four integers per line: the first integer on the line is the -based index of the command whose detail is to be changed, followed by 3 integers, , , , the new description of the command.

#### Output Specification

For each change, print 4 lines, the final configuration of the formation after the modifications so far.

#### Sample Input

2 4
1 1 1
1 1 1
1 1 1 2
2 2 2 3
1 1 1 1
2 1 1 4

#### Output for Sample Input

5 1 3 4
6 2 7 8
9 10 11 12
13 14 15 16
5 1 3 4
6 10 2 7
9 14 11 8
13 15 16 12
1 2 3 4
5 10 6 7
9 14 11 8
13 15 16 12
5 1 2 3
9 6 7 4
13 10 11 8
14 15 16 12

#### Description of Output for Sample Input

The two commands leave the configuration unchanged. The first change on the initial configuration causes the configuration to become the first configuration in this problem statement. That is,

The second change takes this configuration and applies .

The next change alters the first change to be the "original" graph, and then, since the second command has been changed to , we have

The last change causes the second command to be which rotates the outermost perimeter of the previous output.

## Comments

There are no comments at the moment.