#B3726. String Insertion and Query Operations
String Insertion and Query Operations
String Insertion and Query Operations
Farmer John has (n) strings, where the (i)-th string is denoted by (s_i). You are required to perform (q) operations on these strings. The operations are of two types:
1 x y i
: Insert the entire string \(s_x\) into string \(s_y\) immediately after its \(i\)-th character. In other words, update \(s_y\) to be
\( s_y = s_y[1\ldots i] + s_x + s_y[i+1\ldots |s_y|] \).2 y
: Output the current value of string \(s_y\).
For example, if \(s_1 = \texttt{abc}\) and \(s_2 = \texttt{xyz}\), then after the operation
1 2 1 2
(inserting \(s_2\) into \(s_1\) after its 2nd character), \(s_1\) becomes \(\texttt{abxyzc}\) while \(s_2\) remains \(\texttt{xyz}\).
inputFormat
The input begins with a line containing two integers (n) and (q) — the number of strings and the number of operations, respectively. This is followed by (n) lines, each containing a non-empty string (s_i). After that, there are (q) lines, each representing an operation in one of the following formats:
1 x y i
: Insert string \(s_x\) into string \(s_y\) after its \(i\)-th character (1-indexed).2 y
: Output the current string \(s_y\).
outputFormat
For every operation of type 2, output the current version of string (s_y) on a separate line.
sample
2 2
abc
xyz
1 2 1 2
2 1
abxyzc