Dipper and the Machine
Time limit2sMemory limit1024 MB
Given range-append operations on n strings, answer substring queries on the accumulated string of a single slot.
- Level
Hard8 of 10
- Topics
- Segment tree, Binary search, Implementation
- Solved
- No attempts yet
Problem
Dipper found a strange machine in the attic today. The machine has slots numbered from 1 to , placed in a row. Each slot holds a string. At the start, every slot holds an empty string. Given , , and , the machine appends the string to the end of every string in slots through .
Dipper bet Mabel that she cannot model the machine. Dipper issues commands, and Mabel repeats each one in parallel. To check that Mabel copies the machine's behavior exactly, Dipper sometimes asks: what is the substring from position to position of the string in slot ? Mabel wants a program that simulates this process. Help her.
Input
The first line contains two positive integers and , the number of slots and the number of Dipper's commands (; ).
Each of the next lines contains one command, which has one of two types:
- 1 : append the non-empty string to the end of every string in slots through inclusive (). The string consists of lowercase Latin letters.
- 2 : find the substring from to inclusive of the string in slot (; ). The length of the string in slot is guaranteed to be at least .
The total length of strings in type 1 commands does not exceed . The total length of substrings requested by type 2 commands does not exceed .
Output
For each command of type 2, print the answer on a separate line.