Benny and String

1

1 votes
Approved, Data Structures, Medium, Segment Trees
Problem

Benny loves strings! She also loves to play with string and make different queries on them.

In this problem Benny has a string s of length n consisting of lowercase Latin letters.

Let's define next letter for every lowercase Latin letter. For letters from 'a' to 'y' next letter is next one in Latin alphabet, and for 'z' the next one is 'a'.

Let's call the rotation of letter is when we replace it with the next one.

You have to answer the following queries about the string s:

  • ? l r c — where c is lowercase Latin letter, (1lrn). You have to output the length of the largest sequence consisting of consecutive letters c in s[l,r], where s[l,r] — is the substring of string s starting with sl and ending with sr.
  • + l r x — you have to rotate every letter in s[l,r] exactly x times, (1lrn), (0x109).
  • * i c — set si equal to c, where c is some Latin lowercase letter, (1in).
  • - i x — set si equal to its value before processing the x-th query, (1in), (1xj), where j is the index of current query. All queries are indexed starting with 1.

Input format

The first line contains two integers n and q denoting the length of the string and the number of queries.

The next line contains string s.

The following q lines contains queries.

Constraints

1n,q105
String s consists of lowercase Latin letters.
There is at least one query of the first type.

Output format

For each query of the first type output an answer as a single integer.

Time Limit: 2.5
Memory Limit: 256
Source Limit:
Explanation

Let's take a look at how string s will look like after each query:

abcaccaccccccccaccacc

Editor Image

?