#SGM0000049. Hoán vị bảng chữ cái (Alphabet Permutations)
Hoán vị bảng chữ cái (Alphabet Permutations)
Alphabet Permutations
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain a string over the first letters. Range assignments modify the string. For a permutation , output the minimum number of repeated copies of needed so that the current string is a subsequence.
Input
The first line contains , followed by string . Then operations follow: 1 l r c assigns character on the range, while 2 p asks for for a permutation of the first letters.
Output
For every type-2 operation, print .
Subtasks
-
Subtask 1 (20%): size and operation count at most 30; all other validity conditions are unchanged.
-
Subtask 2 (30%): size and operation count at most 3000; all other validity conditions are unchanged.
-
Subtask 3 (50%): full constraints:
-
-
-
Examples
Input
7 4 3
abacaba
1 3 5 b
2 abc
1 4 4 c
2 cba
Output
6
5
Explanation
After the first assignment the string is abbbbba; permutation abc needs 6 copies. After the next assignment the string is abbcbba; permutation cba needs 5 copies.