CF367A.Sereja and Algorithm
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q=q1q2... qk . The algorithm consists of two steps:
- Find any continuous subsequence (substring) of three characters of string q , which doesn't equal to either string "zyx", "xzy", "yxz". If q doesn't contain any such subsequence, terminate the algorithm, otherwise go to step 2.
- Rearrange the letters of the found subsequence randomly and go to step 1.
Sereja thinks that the algorithm works correctly on string q if there is a non-zero probability that the algorithm will be terminated. But if the algorithm anyway will work for infinitely long on a string, then we consider the algorithm to work incorrectly on this string.
Sereja wants to test his algorithm. For that, he has string s=s1s2... sn , consisting of n characters. The boy conducts a series of m tests. As the i -th test, he sends substring slisli+1... sri (1<=li<=ri<=n) to the algorithm input. Unfortunately, the implementation of his algorithm works too long, so Sereja asked you to help. For each test (li,ri) determine if the algorithm works correctly on this test or not.
输入格式
The first line contains non-empty string s , its length ( n ) doesn't exceed 105 . It is guaranteed that string s only contains characters: 'x', 'y', 'z'.
The second line contains integer m (1<=m<=105) — the number of tests. Next m lines contain the tests. The i -th line contains a pair of integers li , ri (1<=li<=ri<=n) .
输出格式
For each test, print "YES" (without the quotes) if the algorithm works correctly on the corresponding test and "NO" (without the quotes) otherwise.
输入输出样例
输入#1
zyxxxxxxyyz 5 5 5 1 3 1 11 1 4 3 6
输出#1
YES YES NO YES NO
说明/提示
In the first example, in test one and two the algorithm will always be terminated in one step. In the fourth test you can get string "xzyx" on which the algorithm will terminate. In all other tests the algorithm doesn't work correctly.