OKRET - Okret
There is a text consisting of N characters. At each step Mirko chooses two numbers A and B and then reverses the subsequence consisting of characters between indices A and B, inclusive. Indices are 1-based.
Write a program that prints the final text after all operations are made.
The first line of input contains the initial text of length N (1 ≤ N ≤ 2500000). It consists only of lowercase letters of the English alphabet.
The second line contains integer M (1 ≤ M ≤ 2500), the number of steps.
Each of the following M lines contain two integer A and B (1 ≤ A ≤ B ≤ N).
In the first and only line output the final text.
(Tjandra Satria Gunawan)(æ›¾æ¯…æ˜†):
O(N+M^2)is the best complexity(?) :-D
@Prateek, because it's too slow
can someone tell me that why it can't be done by just using STL.....using some special functions provided in string library..
i want know explanation for the examples ....