Editorial for Rohan and Rotations

Can someone provide editorial for this problem from hackerearth

Notice that the given array never actually changes: every element always has the same element before it and the same element after it. So we only need to save the index of the start of the array. For operation 1, you increment the index by 1, and if it’s now equal to n, change it to 0, and for operation 2 you decrement it by 1, and if it’s now equal to -1, change it to n - 1. At the end of the algorithm just print the array starting from this index, circularly. (print the segment from index to n - 1 and then from 0 to index - 1)

Hope this helps you. AC code: #include <iostream>using namespace std;int n, q, x, a[100010], index;i - Pastebin.com

The problem can be solved by accumulating the total number of net rotations and its type.

Observations:

  1. Equal number of clockwise and anti-clockwise rotations leave no effect on the array.
  2. If there are net x rotations, then the result will be same as that of x mod n rotations as after every n rotations of either type, the array reaches its original state.

Keeping in mind these things you can easily say that if there are net a rotations of anti-clockwise type then the answer array will be answer[(i-a)%n] = array[i].
Similarly if there are net c rotations in clockwise sense then the answer array will be answer[(i+a)%n] = array[i].

Just keep in mind the negative modulus.

Working code can be found here