Alphabet Queries (Hard)
Time limit2sMemory limit1024 MB
For a string of uppercase letters, count maximal same-letter runs in a substring and shift the letters in a range forward by one, cyclically.
- Level
Medium6 of 10
- Topics
- Segment tree, String
- Solved
- No attempts yet
Problem
This version differs from the Easy version only in the limits of and .
A substring that satisfies both conditions below is called a letter block.
- It consists of one repeated letter only.
- If a longer substring of the whole string that contains it can form a letter block, then it is not a letter block.
For example, in the string AAABBAAC, the letter blocks are AAA, BB, AA, and C, four in total. In the same string, B and AC do not satisfy the conditions, so they are not letter blocks.
You are given a string of length made only of uppercase English letters. Write a program that handles the following queries.
1 l r: Print the number of letter blocks in the substring .2 l r: Change every letter in the substring to the next letter in alphabetical order.ZbecomesA.
The substring contains all characters from position through position of , in order.
Input
The first line contains the string length and the number of queries , separated by a space.
The second line contains the string of length , made only of uppercase English letters.
Each of the next lines contains one query.
At least one query of type is given.
Output
For each query of type , print the result on its own line, in the order the queries are given.