#C10069. Process String Operations

    ID: 39233 Type: Default 1000ms 256MiB

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) of S with character c.
  • Type 2: 2 L R — Query the length of the longest substring with all distinct characters in the substring S[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:

    1. A single line containing the initial string S.
    2. A line containing an integer Q which represents the number of operations.
    3. Q lines follow, each describing an operation in one of the two formats:
      • 1 x c — update the character at position x to character c.
      • 2 L R — query the length of the longest substring with unique characters in the subarray S[L...R].

    outputFormat

    For each type 2 query, output the result as an integer on a new line to standard output (stdout). There should be no output for type 1 operations.

    ## sample
    abcdefgh
    3
    2 1 8
    1 3 z
    2 2 7
    8
    

    6

    </p>