#C10069. Process String Operations
Process String Operations
Process String Operations
You are given an initial string S
and a series of Q operations. There are two types of operations:
- Type 1:
1 x c
— Replace the character at the x-th position (1-indexed) ofS
with characterc
. - Type 2:
2 L R
— Query the length of the longest substring with all distinct characters in the substringS[L...R]
(1-indexed). This can be mathematically represented as finding the maximum k such that for some index i with L ≤ i ≤ R-k+1, the substring SiSi+1...Si+k-1 satisfies \[ \forall\; j, \ell \; (0 \le j < \ell < k \Rightarrow S_{i+j} \neq S_{i+\ell}), \] where all characters are distinct.</p>You should process the operations in the given order and for each type 2 operation output the computed result on a new line.
Note: The operations must be processed sequentially, and changes made by type 1 operations affect the subsequent queries.
inputFormat
The input is read from standard input (
stdin
) and is structured as follows:- A single line containing the initial string
S
. - A line containing an integer
Q
which represents the number of operations. Q
lines follow, each describing an operation in one of the two formats:1 x c
— update the character at positionx
to characterc
.2 L R
— query the length of the longest substring with unique characters in the subarrayS[L...R]
.
outputFormat
For each type 2 query, output the result as an integer on a new line to standard output (
## samplestdout
). There should be no output for type 1 operations.abcdefgh 3 2 1 8 1 3 z 2 2 7
</p>8
6
- A single line containing the initial string