TCCC '23 Nov P4 - Special Sequential Letter Sequences
View as PDFA sequence of letters is called a word. A sequence of letters is considered special if all the characters within the word are unique (There are no duplicate letters).
Given a sequence of letters and
queries, for each query, determine the number of possible Special Sequences that can be created using all the unique characters between index
and
(inclusive) of string
.
Input Specification
The first line will consist of two integers
and
, the length of string
and the number of queries.
The next line will contain a single string of length
consisting of uppercase characters between
A to Z.
The last lines will consist of 2 integers,
and
, representing a query using characters between
and
(inclusive) of string
.
Output Specification
For each query , output the number of possible Special Sequences using characters between the
th and
th character of string
Subtasks
Subtask 1 [10%]:
Subtask 2 [20%]:
Subtask 3 [70%]:
- No further constraints
Sample Input 1
3 1
XYZ
1 3
Sample Output 1
6
Explanation for Sample Output 1
There are a total of 6 unique Special Sequences using characters between indices 1 and 3:
XYZ, XZY, YXZ, YZX, ZXY, ZYX.
Sample Input 2
9 4
SSSUUUSSS
1 3
3 4
4 6
1 9
Sample Output 2
1
2
1
2
Explanation of Sample Output 2
The only possible Special Sequence using characters between indices 1 and 3 is S.
The two characters between 3 and 4 are S and U, the only possible Special Sequences are SU and US
The only possible Special Sequence using characters between indices 4 and 6 is U.
The two characters unique characters between 1 and 10 are S and U, the only possible Special Sequences are SU and US
Sample Input 3
26 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1 26
Sample Output 3
49626704
Explanation for Sample Output 3
Make sure to output your answer
.
Comments