#P7647. [COCI 2012/2013 #5] ROTIRAJ

[COCI 2012/2013 #5] ROTIRAJ

题目描述

Mislav and Marko have devised a new game, creatively named Rotate. First, Mirko imagines a number sequence of length NN and divides it into sections, with each section containing KK numbers (KK evenly divides NN). The first section contains numbers in the first KK positions in the sequence, the second section the following KK positions, and so on.

Then, Marko asks Mislav to apply a number of operations on the sequence, with each operation being one of the following two types:

  1. Rotate the numbers in each section to the left/right by XX positions
  2. Rotate the whole sequence to the left/right by XX positions

Notice that an operation of type 2 can change the numbers belonging to each section. After applying all the operations, Mislav reveals the final sequence to Marko. Marko's task is finding Mislav's starting sequence. He has asked you for help.

输入格式

The first line of input contains three positive integers: NN ( 1N1000001 \le N \le 100000 ), the length of the sequence, KK ( 1K1000001 \le K \le 100000 ), the size of each section, and QQ ( 1Q1000001 \le Q \le 100000 ), the number of operations.

Each of the following QQ lines contains two integers: AA ( 1A21 \le A \le 2 ), the operation type, and XX ( 100000X100000-100000 \le X \le 100000 ), the number of positions to rotate by. A negative number represents rotation to the left, while a positive one represents rotation to the right.

The last line of input contains NN space-separated integers ZiZ_i ( 0Zi1000000 \le Z_i \le 100000 ) representing the final sequence (after applying all operations).

输出格式

The first and only line of output must contain the required starting sequence.

4 2 2
2 2
1 1
3 2 1 0
0 1 2 3
8 4 4
1 3
1 15
1 -5
2 -1
6 10 14 19 2 16 17 1
6 10 14 1 2 16 17 19
9 3 5
1 1
2 -8
2 9
1 1
2 -4
3 1 8 7 4 5 2 6 9
5 3 6 9 7 1 8 2 4

提示

SCORING

In test data worth at least 40%40\% of total points, NN will be at most 100100. In test data worth at least 70%70\% of total points, KK will be at most 100100.

Clarification of the first example

The starting sequence is 0 1 2 30\ 1\ 2\ 3. After the first operation, the sequence is 2 3 0 12\ 3\ 0\ 1, and after the second operation, it becomes 3 2 1 03\ 2\ 1\ 0. This corresponds to the final sequence.

Source:COCI2012_2013 CONTEST #5 T5 ROTIRAJ