Monk and Match Making

3.8

129 votes
Medium, Open, Approved, Hash table, Hash function
Problem

Monk has magical powers, by which he can compare any part of the strings and figure out if they're equal. His magical powers are faster than a super computer even. So, to prove his worth, he's given a string and he has to answer multiple queries based on the string.

Every query will have four integers - L1, R1, L2, R2. The first two integers denoting String [ L1, R1 ] (including both L1 and R1) denoting the first substring, the next two integers denoting the second substring String [ L2, R2 ] (including both L2 and R2).

For every query, you've to answer in Yes or No whether the two substrings are equal or not. Easy enough?

Input:
The first line contains a string, S.
Then, an integer Q denoting the number of queries in the next line.
Then, for every query, there will be 4 integers L1 R1 L2 R2, denoting the substring S[L1 R1] and S[L2 R2].

Output:
For each query output "Yes" if the two substrings are same , else output "No".

Constraints:
1 ≤ |S| ≤ 105
1 ≤ Q ≤ 105
1 ≤ L1R1 ≤ |S|
1 ≤ L2R2 ≤ |S|
The string will contain only lowercase letters.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For Query 1 , it denotes the substrings "m" and "n" which do not match
For Query 2 , it denotes the substrings "monk" and "monk" which do match
For Query 3 , it denotes the substrings "n" and "n" which do match
For Query 4 , it denotes the substrings "ka" and "ki" which do not match

Editor Image

?