#P7647. Recover the Original Sequence
Recover the Original Sequence
Recover the Original Sequence
You are given a sequence of length \(N\) that was originally partitioned into \(\frac{N}{K}\) contiguous subsequences, each containing exactly \(K\) numbers (it is guaranteed that \(K\) divides \(N\)). Two kinds of operations are applied in sequence on the original sequence:
- Operation 1 (Group Shift): For each subsequence (group), shift the numbers within the group by \(X\) positions to the left or right. Note: This operation does not change which numbers belong to each group.
- Operation 2 (Global Shift): Treat the sequence as a whole and shift all numbers by \(X\) positions to the left or right. This is the only operation that can change the composition of the subsequences.
You are given the final sequence after all operations were applied as well as the list of operations (in the order they were applied). Your task is to recover the original sequence.
Note: All shifts are cyclic. For a left shift, the elements that go off the left end reappear at the right end, and vice versa.
inputFormat
The first line contains two integers \(N\) and \(K\) (with \(K\) dividing \(N\)).
The second line contains \(N\) space-separated integers representing the final sequence after all operations.
The third line contains an integer \(M\) denoting the number of operations.
Each of the next \(M\) lines contains an operation in the format:
t d X
where:
- \(t\) is either
1
(group shift) or2
(global shift). d
is a character:L
for left shift orR
for right shift.- \(X\) is a positive integer representing the number of positions to shift.
outputFormat
Output the original sequence as \(N\) space-separated integers.
sample
6 3
6 4 2 3 1 5
2
1 L 1
2 R 2
1 2 3 4 5 6