Advance search problem

3

10 votes
Advanced Data Structures, Segment Trees, Data Structures
Problem

You are given a string S of length N consisting of only lower case English alphabets. You will need to answer Q queries of the following types.

  • 1 L R W: Find the number of occurrences of string W in substring [L,R] of string S.
  • 1 L R U: Update the substring [L,R] of string S with string U.

Input format

  • The first line contains two space-separated integers N and Q.
  • The second line contains a string S of length N.
  • Next Q lines contains queries of two types as given in the problem statement.

Output format

For each query of type 1

  • You are required to print the number of occurrences of string W in substring [L,R] of string S in a new line.

Constraints

1N105

1LRN

|W|min(RL+1,10)

|U|=RL+1

Qi=1|W|106

Qi=1|U|105

Time Limit: 5
Memory Limit: 512
Source Limit:
Explanation

In first query we have to find no of occurrences of string "ana" in substring "anananb" which is 2

In second query the string becomes "nananana"

In last query we have to find no of occurrences of string "ana" in substring "ananana" which is now  3

 

Editor Image

?