#K14516. Substring Operations: Left Rotation and Distinct Characters Query
Substring Operations: Left Rotation and Distinct Characters Query
Substring Operations: Left Rotation and Distinct Characters Query
You are given a string (S) of length (n) and a sequence of (Q) operations to perform on it. There are two types of operations:
Type 1: Rotate the substring (S[L:R]) to the left by (K) positions. This means moving the first (K) characters of the substring to the end of the substring. Formally, if (T = S[L:R]), then after a left rotation by (K), the substring becomes (T' = T[K+1:] + T[1:K]).
Type 2: Query the number of distinct characters in the substring (S[L:R]).
All indices are 1-indexed. Process the operations in the given order and for every Type 2 operation, output the result.
inputFormat
The input is given via standard input (stdin).
The first line contains an integer (n) — the length of the string (S).
The second line contains the string (S) consisting of (n) characters.
The third line contains an integer (Q) — the number of operations.
Each of the next (Q) lines represents an operation and is in one of the following formats:
- For Type 1 operations:
1 L R K
(rotate substring \(S[L:R]\) left by \(K\) positions). - For Type 2 operations:
2 L R
(query distinct characters in \(S[L:R]\)).
outputFormat
For each Type 2 operation, output a single line containing the number of distinct characters in the specified substring. The output should be printed via standard output (stdout).## sample
7
abacaba
5
2 1 3
1 2 5 2
2 1 3
1 1 7 3
2 4 6
2
2
2
</p>