CF367A.Sereja and Algorithm

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

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 = _q_1_q_2... q__k. The algorithm consists of two steps:

  1. 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.
  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 = _s_1_s_2... s__n, consisting of n characters. The boy conducts a series of m tests. As the i-th test, he sends substring s__l__i__s__l__i + 1... s__r__i (1 ≤ l__i ≤ r__i ≤ n) to the algorithm input. Unfortunately, the implementation of his algorithm works too long, so Sereja asked you to help. For each test (l__i, r__i) determine if the algorithm works correctly on this test or not.

Sereja 喜欢各种各样的算法。他最近提出了一种新算法,该算法以一个字符串作为输入。我们将该算法的输入字符串记为 q=q1q2…qkq = q_1 q_2 \dots q_k。该算法包含两个步骤:

  1. 在字符串 qq 中寻找任意一个长度为三的连续子串(即子序列),使得该子串既不等于字符串 "zyx",也不等于 "xzy",也不等于 "yxz"。若 qq 中不存在这样的子串,则算法终止;否则,进入步骤 2。
  2. 随机重排所找到的该三字符子串中三个字母的顺序,然后返回步骤 1。

Sereja 认为:若存在非零概率使该算法最终终止,则称该算法在字符串 qq 上工作正确;但若该算法必然在该字符串上无限运行下去,则称该算法在该字符串上工作不正确。

Sereja 想要测试他的算法。为此,他拥有一个由 nn 个字符组成的字符串 s=s1s2…sns = s_1 s_2 \dots s_n。该男孩将进行 mm 次测试。第 ii 次测试中,他将子串 slisli+1…sris_{l_i} s_{l_i+1} \dots s_{r_i}(其中 1≤li≤ri≤n1 \le l_i \le r_i \le n)作为算法的输入。不幸的是,该算法的实现运行时间过长,因此 Sereja 请求你提供帮助。对于每次测试 (li,ri)(l_i, r_i),请判断该算法在此测试上是否工作正确。

输入格式

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 l__i, r__i (1 ≤ l__i ≤ r__i ≤ n).

第一行包含一个非空字符串 ss,其长度 nn 不超过 10510^5。保证字符串 ss 仅由字符 'x'、'y'、'z' 组成。

第二行包含一个整数 mm(1 ≤ m ≤ 1051 \leq m \leq 10^5)—— 测试用例的数量。接下来的 mm 行为测试用例。第 ii 行包含一对整数 lil_i、rir_i(1 ≤ li ≤ ri ≤ n1 \leq l_i \leq r_i \leq n)。

输出格式

For each test, print "YES" (without the quotes) if the algorithm works correctly on the corresponding test and "NO" (without the quotes) otherwise.

对于每个测试用例,如果该算法在对应测试用例上运行正确,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。

输入输出样例

  • 输入#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.

在第一个例子中,测试一和测试二的算法总是在一步内终止。在第四次测试中,可以得到字符串“xzyx”,算法将在该字符串上终止。在所有其他测试中,算法无法正确运行。

输入解题思路,AI测评打分。不知道怎么写?

首页