#C6433. Longest Unique Substring Queries

    ID: 50193 Type: Default 1000ms 256MiB

Longest Unique Substring Queries

Longest Unique Substring Queries

You are given a string ss and an integer qq denoting the number of queries. Each query is defined by two integers ll and rr, representing the range (1-indexed) within the string. For each query, consider the substring s[lr]s[l \ldots r] and determine the length of the longest substring within this segment that contains only unique characters.

The problem requires you to read input from standard input and print the answer for each query on a new line to standard output. Use efficient techniques (such as the sliding window algorithm) to solve the problem.

inputFormat

The input is provided via standard input in the following format:

  1. The first line contains the string ss.
  2. The second line contains an integer qq, the number of queries.
  3. Each of the next qq lines contains two space-separated integers ll and rr, representing a query.

It is guaranteed that 1lrs1 \leq l \leq r \leq |s|.

outputFormat

For each query, output a single integer representing the length of the longest substring with all unique characters in the specified range. Each result should be printed on its own line via standard output.## sample

abcdea
3
1 5
2 4
1 6
5

3 5

</p>