When u are checking freq[r-2] u are checking the substring starting from position r-2 and ending at r. (Since base case is substring with length 3) 
If u check freq[r] u will be checking substring with position r,r+1,r+2 which is outside range [l,r] and also out of bounds for r>n-2
It’s explained in the editorial itself
In other words, it’s not possible to have a longer rich substring without having a smaller 3-length rich substring in it. So it’s enough to check for substrings of length 3 as any rich substring must be made up of at least one of these.
Can you tell me why I am getting TLE for this submission : CodeChef: Practical coding for everyone .
It answers each query in O(1) time and take O(n) time to pre-process. Total time-complexity is O(n * t + q * t). I am not able to figure out why I am getting a TLE.
Try || instead of && in line 56
it still gives wrong answer? but why || will be true since both condition should be true for YES.
I agree that instead of segtree prefix sums are better in this particular problem but for the bonus or problems similar to the bonus you might encounter somewhere else segment trees are required.
Bro, I have done exactly the same thing, but am getting WA . I have checked many test cases. Will you plz check my code once.
https://www.codechef.com/viewsolution/26024140
I’ll give you a hint : Line 59 
I can’t really spot any mistake other than the array size of count. But when I was trying to compile the program sometimes it was showing some errors, and sometimes working properly. I don’t know much java and thus why that was happening. Do check the count array size anyway. Logically it looks correct to me.
Yess, I changed the count size still it did not work. If anyone can find the problem other than array size of count, then plz tell. BTW thank you derco .
I think newtech66 is checking for every digit, so that guarantees checking the left and the right. Say there is a string “aaaabc”. It is rich. “aaa” is rich and “abc” is not. Using a boolean array will give you something like this[true, true, true, false, false, false], meaning at i-th position, the substring string[i:i+2] is rich
Why rating for august cook-off is not revealed till now??

The hint is for you only 
You’re unnecessarily printing “NO” after taking the input n and ignoring the string as well as the subsequent queries.
I did almost same thing but getting TLE …Can you check it…
https://www.codechef.com/viewsolution/26022099
It is giving tle because we are taking Q queries for every test cases. So you need to use FAST IO in this case. I submitted your code using fast IO.
So sorry and yes thank you also.
Add these 2 lines at the start of your main():
std::cout.sync_with_stdio(false);
cin.tie(0);