Last Word
Time limit1sMemory limit512 MB
Given a string and a sequence of substring(start, length) operations, output the characters that survive after all operations are applied in order.
- Level
Medium4 of 10
- Topics
- String, Simulation, Implementation, Array
- Solved
- No attempts yet
Problem
The substring() function is a common operation on strings in most programming languages. It takes a start offset and a length, and builds a new string containing the characters in a sequence of that length beginning at the offset.
A certain string has had this function called on it a large number of times in a row. Using the standard library function substring(s, start, length) to chop it up repeatedly, what remains now is a possibly much shorter string.
Find the string that remains after all of these operations.
Input
- The first line contains the string s (1 ≤ |s| ≤ 106).
- The second line contains the number of operations n (1 ≤ n ≤ 106).
- Each of the next n lines contains two integers starti and lengthi (0 ≤ starti < lengthi−1; 1 ≤ starti + lengthi ≤ lengthi−1).
Output
Output the string after all of the successive substring() operations.