Codeforces Round #616 (Div. 2) D. Irreducible Anagrams 找规律

D. Irreducible Anagrams

time limit per test2 seconds
memory limit per test256 megabytes

Let’s call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.

Let’s consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k≥2 and 2k non-empty strings s1,t1,s2,t2,…,sk,tk that satisfy the following conditions:

If we write the strings s1,s2,…,sk in order, the resulting string will be equal to s;
If we write the strings t1,t2,…,tk in order, the resulting string will be equal to t;
For all integers i between 1 and k inclusive, si and ti are anagrams of each other.

If such strings don’t exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other.

For example, consider the string s= “gamegame”. Then the string t= “megamage” is a reducible anagram of s, we may choose for example s1= “game”, s2= “gam”, s3= “e” and t1= “mega”, t2= “mag”, t3= “e”:

On the other hand, we can prove that t= “memegaga” is an irreducible anagram of s.

You will be given a string s and q queries, represented by two integers 1≤l≤r≤|s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram.

Input

The first line contains a string s, consisting of lowercase English characters (1≤|s|≤2⋅105).

The second line contains a single integer q (1≤q≤105) — the number of queries.

Each of the following q lines contain two integers l and r (1≤l≤r≤|s|), representing a query for the substring of s formed by characters from the l-th to the r-th.

Output

For each query, print a single line containing “Yes” (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing “No” (without quotes) otherwise.

Examples

input
aaaaa
3
1 1
2 4
5 5
output
Yes
No
Yes
input
aabbbbbbc
6
1 2
2 4
2 2
1 9
5 7
3 5
output
No
Yes
Yes
Yes
No
No

Note

In the first sample, in the first and third queries, the substring is “a”, which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain “a”. On the other hand, in the second query, the substring is “aaa”, which has no irreducible anagrams: its only anagram is itself, and we may choose s1= “a”, s2= “aa”, t1= “a”, t2= “aa” to show that it is a reducible anagram.

In the second query of the second sample, the substring is “abb”, which has, for example, “bba” as an irreducible anagram.

定义anagram,表示两个字符串的字符组成相同。

定义reducible anagram,表示可以两个字符串可以拆分成k个子串,且每个子串都是anagram的。

irreducible anagram 就是不满足条件的。

现在给你一个字符串,然后q次询问,每次询问给你l,r。问你[l,r]的这个字符串,能否找到一个irreducible anagram。

只有三种情况能够找到。

#include<bits stdc++.h>
using namespace std;
string s;
int q;
int cnt[26][200005];
int main(){
    cin>>s;
    cin>>q;
    for(int i=0;i<s.size();i++){ cnt[s[i]-'a'][i]++; if(i>0){
            for(int j=0;j<26;j++){ cnt[j][i]+="cnt[j][i-1];" } for(int i="0;i<q;i++){" int l,r; cin>>l>>r;l--,r--;
        if(l==r){
            cout<<"yes"<<endl; continue; } if(s[l]!="s[r]){" cout<<"yes"<<endl; int cnt="0;" for(int j="0;j<26;j++){" r="cnt[j][r];" l="0;" if(l>0)L=cnt[j][l-1];
            if(R-L>0)Cnt++;
        }
        if(Cnt>2){
            cout<<"yes"<<endl; continue; } cout<<"no"<<endl; < code></"yes"<<endl;></"yes"<<endl;></26;j++){></s.size();i++){></bits>

Original: https://www.cnblogs.com/qscqesze/p/12256902.html
Author: qscqesze
Title: Codeforces Round #616 (Div. 2) D. Irreducible Anagrams 找规律

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/553162/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • kafka学习

    Kafka概述 Kafka是分布式(点对点模式)(发布-订阅模式)消息系统,由Scala 写成, 它主要用于处理流式数据。本质是基于消息队列缓存数据. Kafka对消息保存时根据T…

    技术杂谈 2023年7月24日
    0107
  • 编程模式-表驱动编程

    刚开始编程时,往往会碰到一些根据不同条件执行不同功能的情况,通常都是采用if-else或者switch-case的方式,如果有很多的情况需要区分,则会有很多的 else if 或者…

    技术杂谈 2023年7月25日
    085
  • 《码出高效》Chapter2面向对象-读书笔记

    《码出高效Java开发手册》第2章 面向对象 面向对象的抽象、封装、继承、多态的理念,使企业应用大规模化成为可能,有效地降低了软件开发成本、维护成本和复用成本。OOP实践了软件工程…

    技术杂谈 2023年7月10日
    074
  • 浅谈K库(转)

    首先要解释什么是K库,记得当年查遍K开头的单词也没有找到答案,后来才知道所谓的K指的是谐音”characterization”,意思是表征。所谓的K库指的是…

    技术杂谈 2023年6月1日
    099
  • 软件质量属性Quality attributes 总结

    Quality attributes have been of interest to the software community at least since the 1970…

    技术杂谈 2023年5月31日
    0100
  • Qt学习笔记

    联系方式 QQ: 2653728884 ,加Q请注明添加原因! Original: https://www.cnblogs.com/arminker/p/5121596.htmlA…

    技术杂谈 2023年7月11日
    072
  • 关于 jar包和 打jar包

    1.什么是 jar包? 2.为什么 要打jar包? 3.jar包 的内部结构? 4.关于 MANIFEST.MF 5.怎样用 jar 进行打jar 包? 6.怎样是用 idea打 …

    技术杂谈 2023年7月11日
    090
  • 微信支付个人接口

    https://payjs.cn/ 服务项目 技术咨询 微信图书 微信视频 微信代码 定制开发 其他福利 服务入口 QQ群有问必答 查看详情一本书解决90%问题查看详情 微信开发视…

    技术杂谈 2023年5月31日
    087
  • 羊了个羊,但是Python简(li)单(pu)版

    大家好,欢迎来到 Crossin的编程教室 !要说最近最热门的游戏,那肯定是《羊了个羊》没跑了。 连续上了好几天热搜,火到连央视都来提醒谨防有人利用游戏之名诈骗。但游戏爆火的另一面…

    技术杂谈 2023年7月25日
    0105
  • word另存为pdf时无书签导航的解决办法

    word可以直接另存为pdf格式,方便了word和pdf之间的格式转换,但是在一般的默认情况下,word直接另存为pdf的时候是不创建书签信息的,这样长文档在没有书签标题导航实在是…

    技术杂谈 2023年6月1日
    0209
  • xampp配置局域网访问

    打开 httpd-xampp.conf(/xampp/apache/conf/extra/httpd-xampp.conf)搜索关键字: Order deny,allow 然后在O…

    技术杂谈 2023年5月31日
    098
  • shopify速度评分怎么提升

    shopify速度慢对用户和搜索引擎都不友好,提升shopify速度迫在眉睫!那么,shopify速度评分怎么提升呢?从app、theme code、image、video等几点优…

    技术杂谈 2023年5月31日
    087
  • 使用Webpack和Babel来搭建React应用程序

    用Webpack(npm install -g webpack)代码打包,Webpack大致需要知道三件事: 1)让Webpack知道应用程序或js文件的根目录2)让Webpack…

    技术杂谈 2023年5月31日
    0104
  • 什么是BASH?

    BASH是Bourne Again SHell的缩写。它由Steve Bourne编写,作为原始Bourne Shell(由/ bin / sh表示)的替代品。它结合了原始版本的B…

    技术杂谈 2023年5月31日
    0118
  • 架构设计之设计模式总结

    在实际项目开发中我们会经常使用到设计模式,设计模式是否能够正确、合理、灵活的运用到项目当中,是评判你开发能力的重要指标之一, 这一方面需要你打下牢固的编程基础,同时也需要积累大量的…

    技术杂谈 2023年7月25日
    0107
  • 日志技术简介

    java日志体系 日志的主流体系 日志的用途 软件开发中,我们经常需要去调试程序,做一些信息,状态的输出便于我们查询程序的运行状况。为了让我们能够更加灵活和方便的控制这些调试的信息…

    技术杂谈 2023年6月21日
    0112
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球