The Scariest Story
Time limit1sMemory limit1024 MB
Given a story of space-separated words, answer position lookups between characters and words while processing character inserts and deletes.
- Level
Medium7 of 10
- Topics
- String, Tree, Implementation
- Solved
- No attempts yet
Statement
Little Jack decided to write the scariest story he could to frighten his friends on Halloween.
A story is a non-empty sequence of words separated by spaces. A word is a non-empty sequence of lowercase Latin letters.
The quality of a story depends on its words and also on the characters inside those words.
Jack has already written a story with words. Now he wants to perform operations on it. Each operation either checks how scary the story is or changes it slightly. There are four kinds of operations:
?1 i: find the word number and the position inside that word for the character at position of the story.?2 w p: find the position in the story of the -th character of the -th word.+ i c: insert character (a lowercase letter or a space written as\_) at position of the story.- i: delete the character at position of the story.
Input
The first line contains two integers and separated by a space ().
The second line contains the story: words separated by spaces. The total length of all words does not exceed .
Each of the next lines describes one operation.
?1 i: , where is the current length of the story.?2 w p: and , where is the current number of words and is the length of the -th word.+ i c: . is a lowercase letter or a space (\_).- i: .
At no moment does the story contain two consecutive spaces or a space at the start. Characters in queries of the first type are always letters, not spaces.
Output
For each query of the first type, print the word number and the position inside the word on one line, separated by a space.
For each query of the second type, print the position in the story on its own line.