# Codeforces Round #215_div2_C. Sereja and Algorithm

（虽然原题不是这样描述的……但大意是酱紫问题不大）

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <cctype>
#define bug puts("here");

using namespace std;

typedef long long ll;

const int maxn = 100086;
const int mod = 1000000007;
const double PI = atan(1.0)*4.0;

char a[maxn];
int x[maxn],y[maxn],z[maxn];

int main()
{
scanf("%s",a);
int len = strlen(a);
int i;
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
memset(z,0,sizeof(z));
//做前缀数组
for(i=1;i<=len;i++)
x[i] = x[i-1] + (a[i-1] == 'x');
for(i=1;i<=len;i++)
y[i] = y[i-1] + (a[i-1] == 'y');
for(i=1;i<=len;i++)
z[i] = z[i-1] + (a[i-1] == 'z');
int m;
scanf("%d",&m);
for(i=0;i<m;i++)
{
int l,r;
scanf("%d%d",&l,&r);
int xx,yy,zz;
xx = x[r] - x[l-1];//统计当前区间内x，y，z出现的次数
yy = y[r] - y[l-1];
zz = z[r] - z[l-1];
int lenth = r - l + 1;
if(lenth < 3)
{
puts("YES");
continue;
}
int t1,t2;
t1 = t2 = 0;
if(xx == lenth/3) t1 ++;
else if(xx == lenth/3 + 1) t2++;
if(yy == lenth/3) t1 ++;
else if(yy == lenth/3 + 1) t2++;
if(zz == lenth/3) t1 ++;
else if(zz == lenth/3 + 1) t2++;
if(t2 == lenth%3 && t1 == 3 - t2) puts("YES");
else puts("NO");
}
return 0;
}


• 本文已收录于以下专栏：

## Codeforces Round #243 (Div. 2) C. Sereja and Swaps 解题报告

C. Sereja and Swaps time limit per test 1 second memory limit per test 256 megabytes ...
• kbdwo
• 2014年04月28日 10:56
• 1002

## Codeforces Round #243 (Div. 2) C. Sereja and Swaps

A. Sereja and Swaps time limit per test 1 second memory limit per test 256 megabytes ...

## Codeforces Round #235 (Div. 2)B. Sereja and Contests

B. Sereja and Contests time limit per test 1 second memory limit per test 256 megabytes ...

举报原因： 您举报文章：Codeforces Round #215_div2_C. Sereja and Algorithm 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)