Reversal
InterviewTime limit1sMemory limit256 MB
Apply M substring reversals to a string of up to 2.5 million characters and print the final result.
- Level
Easy3 of 10
- Topics
- String, Implementation, Simulation
- Solved
- No attempts yet
Problem
A text editor holds a string of characters. Mirko performs steps. In each step he picks two numbers and and reverses the substring made of all characters from position to position , inclusive. To reverse it, he swaps the first character of the substring with the last one, the second with the second to last, and so on. Positions in the string are numbered from to .
Write a program that finds the final state of the string after all reversals.
Input
The first line contains the initial string. It consists only of lowercase English letters, and its length is at most . The second line contains a positive integer (), the number of steps. Each of the next lines contains two positive integers and () that describe one step.
Output
Print the string after all reversals on a single line.