Loading repovive.com/problems/classics/39
Given a string s of lowercase letters and q queries, answer each query asking whether two substrings of s are equal.
For each query (l1,r1,l2,r2), determine if the substring s[l1..r1] equals the substring s[l2..r2] (1-indexed, inclusive).
abcabc 3 1 3 4 6 1 2 5 6 2 2 5 5
The substring 1..3 is
abc
, matching 4..6. The substring 1..2 is
ab
, while 5..6 is
bc
. The one-character substrings 2..2 and 5..5 are both
b
.
Yes No Yes
racecar 3 1 1 7 7 1 3 5 7 2 6 2 6
Positions 1 and 7 are both
r
. The substrings 1..3 (
rac
) and 5..7 (
car
) differ. The query 2..6 compared with itself is always equal.
Yes No Yes
aaaaaaa 3 1 3 5 7 1 2 3 4 1 1 7 7
All characters are
a
, so every pair of queried substrings with the same length is equal.
Yes Yes Yes