博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C. Sereja and Algorithm 贪心
阅读量:4965 次
发布时间:2019-06-12

本文共 3322 字,大约阅读时间需要 11 分钟。

C. Sereja and Algorithm
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

 

  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 = 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.

Input

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 liri (1 ≤ li ≤ ri ≤ n).

Output

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

Sample test(s)
input
zyxxxxxxyyz 5 5 5 1 3 1 11 1 4 3 6
output
YES YES NO YES NO
Note

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.

const int maxn = 300000;char s[maxn];int sumx[maxn];int sumy[maxn];int sumz[maxn];int main() {    //freopen("in.txt","r",stdin);    while(scanf("%s",s + 1) == 1)    {        int len = strlen(s + 1);        sumx[0] = sumy[0] = sumz[0] = 0;        repf(i,1,len)        {            if(s[i] == 'x')            {                sumx[i] = sumx[i - 1] + 1;                sumy[i] = sumy[i -1];                sumz[i] = sumz[i - 1];            }            if(s[i] == 'y')            {                sumy[i] = sumy[i - 1] + 1;                sumx[i] = sumx[i -1];                sumz[i] = sumz[i - 1];            }            if(s[i] == 'z')            {                sumz[i] = sumz[i - 1] + 1;                sumy[i] = sumy[i -1];                sumx[i] = sumx[i - 1];            }        }        int m;        cin>>m;        repf(i,1,m)        {            int a,b;            scanf("%d%d",&a,&b);            if(b - a + 1 < 3)            {                cout<<"YES"<
0 && kk > 0 && kkk > 0 && abs(k - kkk) <= 1 && abs(k - kk) <= 1 && abs(kkk - kk) <= 1) cout<<"YES"<

 

转载于:https://www.cnblogs.com/DreamHighWithMe/p/3445362.html

你可能感兴趣的文章
php 位运算与权限,怎么在PHP中使用位运算对网站的权限进行管理
查看>>
php include效率,php include类文件超时
查看>>
matlab sin函数 fft,matlab的fft函数的使用教程
查看>>
wcdma下行如何解扩解扰 matlab,WCDMA技术基础.ppt
查看>>
MySQL date_format() 函数
查看>>
mysql 时间处理
查看>>
mysql adddate()函数
查看>>
mysql addtime() 函数
查看>>
mysql 根据日期时间查询数据
查看>>
mysql 创建时间字段
查看>>
mysql 生成随机数rand()
查看>>
mysql e的n次幂exp()
查看>>
mysql sin() 函数
查看>>
mysql upper() 函数
查看>>
mysql 子查询
查看>>
mysql 自联结
查看>>
mysql union 组合查询
查看>>
socket tcp
查看>>
spiral-matrix-ii &i 生成顺时针序列
查看>>
python set集合方法总结
查看>>