Tanmay and his PROness
Practice
0 (0 votes)
Hard
Problem
22% Success 67 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Argusoft is having problem in designing algorithm for a client under given constraints. So, they hired Tanmay (also known as tanmay273) as he is well known PRO-coder. He solved it in very less time . As He loves to give Good challenges to his juniors, now he wants you to solve the same problem .Here is the problem :

you will be given two string A and B. and he will give you Q queries. each query will consist of two integers L and R, you have to tell how many subsequences of A[L:R] will be equal to B. here A[L:R] denotes substring of A which starts at index L and ends at index R. since answer can be large so you need to tell answer modulo 109+7.

Input
first line will consist of two integer N and M, representing the length of A and B respectively. it will be followed by String A and B. next line will contain Q representing number of queries, next Q line will contain two integers L and R.

Output
for each query output the number of subsequences modulo 109+7

Constraints

1 <= N ,Q <= 250000
1 <= L <= R <= N
1 <= M <= 5

both the strings A and B will be consist of only lower case letters.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
Data StructuresHardSegment treeData Structures
Points:50
8 votes
Tags:
StringLazy Propagation in Interval/Segment TreesData StructuresAdvanced Data Structures
Points:50
2 votes
Tags:
Lazy Propagation in Interval/Segment TreesData StructuresBit manipulationAdvanced Data Structures
Editorial

Login to unlock the editorial