Maintain a lowercase string under block moves, reversals, and single-character insertions, answering after each change whether a given substring reads the same forwards and backwards.
Hard10StringString matchingImplementationNo attempts yetTime limit2sMemory limit256 MBYou are given a string S=s1s2…sn of length n. For x≤y, Sx,y is the substring sx…sy; for x>y, Sx,y is the empty string.
Process m queries in the order they are given. There are two kinds.
Question query. You are given integers i and j. Decide whether the substring Si,j is a palindrome.
Modification query. One of the following three.
The third modification query makes the string one character longer, so n means the length of the string just before the current query is processed.
Write a program that runs the queries above.
The first line contains two space-separated integers n and m. (1≤n≤105, 1≤m≤105)
The second line contains the n characters of the initial string.
Each of the next m lines contains one query.
Q i j. (1≤i≤j≤n)M 1 i j k. (1≤i≤j≤n, 0≤k≤n−(j−i+1))M 2 i j. (1≤i≤j≤n)M 3 i c, where c is a single character. (1≤i≤n+1)On every line, n is the length of the string just before that query is processed. You can assume that the string contains only lowercase letters of the English alphabet at all times. You may assume that the input is valid.
For each question query, print the answer on its own line. Print YES if Si,j is a palindrome and NO otherwise. Do not print the quotes.
In the first example the modification queries change the string like this.
bananaM 2 2 3: S= bnaanaM 2 5 6: S= bnaaanM 3 7 b: S= bnaaanbM 1 1 2 4: S= aaanbnbThe last modification query cuts out the block bn and puts it back after the first four characters of the remaining string aaanb.