All Tracks Problem

Rohan and Rotations
/
No tags
Problem
Editorial
Analytics

Rohan got an array of numbers A from Mohan. Length of array A is n. Mohan asks Rohan to perform 2 different type of operations on array A. The operations are -
(i) Clockwise Rotation - In this operation, the element at index i moves to index (i+1) mod n
(ii) Anticlockwise Rotation - In this operation, the element at index i moves to index (i-1) mod n

Consider the given array as 0-indexed.
Given the initial array A and set of operations, you need to determine the resulting array.

Input Format

First line contains integer n, length of array A
Second line contains n space separated integers denoting the elements of array A
Third line contains integer Q, number of operation to be performed
Fourth line Q space separated integers denoting the set of operations 1 denotes anti-clockwise rotation, while 2 denotes clockwise rotation

Output Format

Output n space-separated integers which is the resulting array

Constraints

  • 1 ≤ n, Q ≤ 100000
  • 1 ≤ A[i] ≤ 109
SAMPLE INPUT
5
1 2 3 4 5
4
1 1 1 2
SAMPLE OUTPUT
3 4 5 1 2
Explanation

After each operation the rotation are as follows -

  • 2, 3, 4, 5, 1
  • 3, 4, 5. 1, 2
  • 4, 5. 1, 2, 3
  • 3, 4, 5. 1, 2

So the resulting array is 3, 4, 5. 1, 2

Time Limit: 5.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB

Best Submission

Similar Problems

Contributors

Initializing Code Editor...
Notifications
View All Notifications

?