#C2382. Longest Unique Substring Ending at Given Positions
Longest Unique Substring Ending at Given Positions
Longest Unique Substring Ending at Given Positions
Given a string (s) consisting of lowercase Latin letters and a sequence of query indices (1-indexed), the goal is to determine, for each query, the length of the longest substring ending at that index which contains no repeated characters. In other words, for each query index (i), find the maximum integer (L) such that the substring (s[j \ldots i]) with (j = i - L + 1) contains all unique characters. This problem requires careful backward traversal from the given index to ensure that each character is unique.
inputFormat
The input is read from standard input (stdin) and consists of four parts:
- The first line contains an integer (n), representing the length of the string.
- The second line contains the string (s) of length (n) composed only of lowercase letters.
- The third line contains an integer (q), representing the number of queries.
- The fourth line contains (q) space-separated integers, each a 1-indexed query position.
outputFormat
For each query, output the length of the longest substring ending at the specified index that contains no repeated characters. Each result should be printed on a new line to standard output (stdout).## sample
10
abcabcabcd
3
5 10 3
3
4
3
</p>