http://codeforces.com/contest/368/problem/C

从左向右记录从1位置到每一个位置上x,y,z的个数。然后判断在l,r区间内的x,y,z的关系满不满足abs(x-y)<=1&&abs(x-z)<=1&&abs(y-z)<=1,满足输出YES,否则输出NO。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200000
using namespace std; char str[maxn];
int hx[maxn],hy[maxn],hz[maxn];
int m;
int l,r; int main()
{
while(scanf("%s",str)!=EOF)
{
int t1=,t2=,t3=;
memset(hx,,sizeof(hx));
memset(hy,,sizeof(hy));
memset(hz,,sizeof(hz));
int len=strlen(str);
for(int i=; i<len; i++)
{
if(str[i]=='x')
{
t1++;
hx[i+]=t1;
hy[i+]=t2;
hz[i+]=t3;
}
else if(str[i]=='y')
{
t2++;
hx[i+]=t1;
hy[i+]=t2;
hz[i+]=t3;
}
else if(str[i]=='z')
{
t3++;
hx[i+]=t1;
hy[i+]=t2;
hz[i+]=t3;
}
}
scanf("%d",&m);
for(int i=; i<=m; i++)
{
scanf("%d%d",&l,&r);
int len=r-l+;
if(len<)
{
printf("YES\n");
continue;
}
else
{
int x=hx[r]-hx[l-];
int y=hy[r]-hy[l-];
int z=hz[r]-hz[l-];
if(abs(x-y)<=&&abs(x-z)<=&&abs(y-z)<=)
{
printf("YES\n");
}
else printf("NO\n");
}
}
}
return ;
}

cf C. Sereja and Algorithm的更多相关文章

  1. Codeforces Round #215 (Div. 2) C. Sereja and Algorithm

    #include <iostream> #include <vector> #include <algorithm> #include <string> ...

  2. cf D. Sereja ans Anagrams

    http://codeforces.com/contest/368/problem/D #include <cstdio> #include <cstring> #includ ...

  3. cf B. Sereja and Suffixes

    http://codeforces.com/contest/368/problem/B 从后往前找一遍就可以. #include <cstdio> #include <cstring ...

  4. CF 314C Sereja and Subsequences(树状数组)

    题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...

  5. 【CF】Sereja and Arcs

    #include <bits/stdc++.h> #define llong long long using namespace std; const int N = 1e5; const ...

  6. Android 签名比较

    一. keytool -list -printcert -jarfile "%filename%" 二. 非常low方法:下载的应用安装能成功覆盖原应用则签名一致三. 作者:陈子腾 ...

  7. Codeforces 367

    A. Sereja and Algorithm 水题不解释. B. Sereja ans Anagrams 模p同余的为一组,随便搞. C. Sereja and the Arrangement of ...

  8. Codeforces Round #215 (Div. 1)

    A Sereja and Algorithm 题意:给定有x,y,z组成的字符串,每次询问某一段s[l, r]能否变成变成zyxzyx的循环体. 分析: 分析每一段x,y,z数目是否满足构成循环体,当 ...

  9. 如何判断 Android 应用的 Apk 签名是否一致?

    可以比对apk签名的fingerprint. 假定安装了JDK,如果想查HelloWorld.apk所使用的签名的fingerprint,可以这样做: 1. 查找apk里的rsa文件 (Windows ...

随机推荐

  1. Android Canvas.drawText方法中的坐标参数的正确解释

    摘要 canvas.drawText(www.jcodecraeer.com, x, y, paint); x和y参数是指定字符串中心的坐标吗?还是左上角的坐标?这个问题的直观印象应该是左上角的坐标, ...

  2. Android取得电池的电量

    首先需要用到的是一个类继承BrocastReceiver 2 代码如下: public class Battery_Info extends BroadcastReceiver { @Override ...

  3. sql sever 模糊查询 除了like还有PATINDEX

    返回模式在指定表达式中第一次出现的起始位置:如果在所有有效的文本和字符数据类型中都找不到该模式,则返回零. USE AdventureWorks2012; GO SELECT PATINDEX('%e ...

  4. WPF自定义下拉控件

    可以搜索的下拉条 using System; using System.Collections; using System.Collections.Generic; using System.Coll ...

  5. (转)Linux下apache限速和限制同一IP连接数的实现

    单位有一台DELL的服务器,4核双CPU,4G内存,1TB的存储空间,闲来无事,申请了域名http://www.zxzy123.cn,做了个网站,本以为用这样的配置做个下载站是绰绰有余了,没想到上线没 ...

  6. 【顽固BUG】Visual Studio 2013 + TestDriven.NET-3.8.2860_Personal_Beta 调用的目标发生了异常。

    前言 突然怎么弄也无法断点调试了 输出如下: ------ Test started: Assembly: Server5.V2.dll ------ 调用的目标发生了异常. 而且网站运行提示: -- ...

  7. C++中数组初始化

    #include<iostream>using std::cout;using std::endl;int arr1[5];int arr2[5] = {1,3,5};int main() ...

  8. jdk\willy\集群安装

    一.telnet用户验证端口: yum install telnet #也可以使用 yum install telnet-ssl 安装支持SSL的telnet方式,这样安全一些,不建议使用标准的tel ...

  9. 服务 Service 基本介绍

    Activity public class MainActivity extends ListActivity {     private boolean flag;//是否开启线程     publ ...

  10. 去除html页面中按钮在ios中的默认样式,去除select自带的小三角图标

    btn{-webkit-appearance: none;} -webkit-appearance: none也能去掉select下拉列表后面自带的小三角