The Alphabetic Rope is now available in the market. The Alphabetic Rope consists of alphabetic characters in each stripe which looks like string.
You are given an Alphabetic rope consists of lowercase alphabetic characters only,you have to perform some operations on rope and answers some queries on it.
Queries are of 3 types:
- 1 X Y : Cut the rope segment from X to Y and Reverse it then join at the front of the rope.
- 2 X Y : Cut the rope segment from X to Y and Reverse it then join at the back of the rope.
- 3 Y: Print on a new line an Alphabet on Yth position of the current rope.
There is only one input. Input begins with single line giving Alphabetic Rope as a string S. Next line containg Q, follows Q lines giving Queries as mentioned above. ( Index used are 0-based )
For each query of type 3, Print a single character in a new line.
gautambishal 5 1 3 5 3 0 3 3 2 2 4 3 9
m g a
- 1 ≤ |S| ≤ 100 000
- 1 ≤ Q ≤ 100 000
- 2 seconds
Problem source: SPOJ