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. [Operationg System Labs] 我对 Linux0.00 中 boot.s的理解和注释

    (如有错误请立即指正,么么哒!) !    boot.s!! It then loads the system at 0x10000, using BIOS interrupts. Thereafte ...

  2. Android 按钮按下效果

    <?xml version="1.0" encoding="utf-8"?><selector xmlns:android="htt ...

  3. openstack neutron debugs lists

  4. lesson6:java线程中断

    正常的情况下,业务系统都不会去中断它的线程,但是由于一些特殊情况的发生,线程已经不能正常结束了,并且此类线程已经影响到业务系统提供服务的能力,如果系统设计的健壮,便会通过监控线程去主动的中断此类线程. ...

  5. Javascript:sort()方法快速实现对数组排序

    定义和用法: sort() 方法用于对数组的元素进行排序. 语法: arrayObject.sort(sortby) 注释:sortby,可选,规定排序顺序,必须是函数. 说明: 如果调用该方法时没有 ...

  6. solr 3.5 配置及server设置

    一.solr 的简单介绍 Apache Solr 是一个开源的搜索server.Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现.Apache Solr 中 ...

  7. MySQL加密的性能测试

    这是对MySQL进行加密性能测试的两篇文章系列之二.在第一篇中,我专门使用MySQL的内置的对SSL的支持来 做压力测试,产生了一些令人惊讶的结果. AD:WOT2015 互联网运维与开发者大会 热销 ...

  8. Linux进程调度与切换

    2016-04-15 张超<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.分析 进程调度的时机与进程 ...

  9. 服务 Service 基本介绍

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

  10. 使用VS Code开发AngularJS 2 第一个应用程序

    使用VS Code开发AngularJS 2 第一个应用程序 目录 运行环境 创建项目 安装依赖包 创建TypeScript应用程序 配置应用程序 运行应用程序 运行环境 运行环境: Windows ...