Under construction

Still being built. Things may change

Alphabet Queries (Hard)

Time limit2sMemory limit1024 MB

Summary
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 NN and QQ.

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 S=S1S2…SNS = S_1 S_2 \dots S_N of length NN 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 SlSl+1…SrS_l S_{l+1} \dots S_r.
  • 2 l r: Change every letter in the substring SlSl+1…SrS_l S_{l+1} \dots S_r to the next letter in alphabetical order. Z becomes A.

The substring SlSl+1…SrS_l S_{l+1} \dots S_r contains all characters from position ll through position rr of SS, in order.

Input

The first line contains the string length NN and the number of queries QQ, separated by a space. (3≤N,Q≤200 000)(3 \leq N, Q \leq 200 \ 000)

The second line contains the string SS of length NN, made only of uppercase English letters.

Each of the next QQ lines contains one query. (1≤l≤r≤N)(1 \leq l \leq r \leq N)

At least one query of type 11 is given.

Output

For each query of type 11, print the result on its own line, in the order the queries are given.

Examples1

  1. Example 1

    Input
    8 5
    AAABBAAC
    1 3 8
    2 2 7
    1 1 8
    2 6 7
    1 1 8
    
    Expected output
    4
    5
    3