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)

大家都在看

  • docker 安装mysql5.7

    拉取镜像 docker pull mysql:5.7 准备数据目录 mkdir -p /mall/docker/mysql/conf mkdir -p /mall/docker/m…

    技术杂谈 2023年7月24日
    089
  • VMware 虚拟机图文安装和配置 Rocky Linux 8.5 教程

    前言这是《VMware 虚拟机图文安装和配置 AlmaLinux OS 8.6 教程》一文的姐妹篇教程,如果你需要阅读它,请点击这里。2020 年,CentOS 宣布:计划未来将重…

    技术杂谈 2023年7月11日
    0106
  • 英国延长 UKCA 标记截止日期

    政府于 2022 年 11 月 14 日宣布,企业将有 2 年的时间来应用新的 UKCA 产品标记。在 2024 年 12 月 31 日之前,企业可以选择使用 UKCA 或 CE …

    技术杂谈 2023年6月21日
    091
  • 一文读懂数据库发展史

    本文力求以简单易懂的语言描述出数据库发展史,尽量避免出现复杂的概念介绍。数据库演进史如图1所示: 图1 数据库演进 一、穿孔纸带和文件系统 在现代意义的数据库出现之前(20世纪60…

    技术杂谈 2023年7月25日
    0105
  • mac 工作区

    https://www.zhihu.com/question/20917614 http://www.bjhee.com/mission-control.html 窗口切换 htt…

    技术杂谈 2023年7月11日
    064
  • Seata启动seata-server.bat闪退

    解决方法:创建logs/seata_gc.log 文件夹及文件 Original: https://www.cnblogs.com/mingforyou/p/15742889.ht…

    技术杂谈 2023年5月31日
    0110
  • elasticsearch通用工具类

    这几天写了一个关于es的工具类,主要封装了业务中常用es的常用方法。 本文中使用到的elasticsearch版本6.7,但实际上也支持es7.x以上版本,因为主要是对spring…

    技术杂谈 2023年7月10日
    069
  • Are You OK?主键、聚集索引、辅助索引

    每张表都一定存在主键吗? 关于这个问题,各位小伙伴们不妨先自己想一想,再往下寻找答案。 首先公布结论: 对于 InnoDB 存储引擎来说,每张表都一定有个主键(Primary Ke…

    技术杂谈 2023年7月24日
    095
  • MySQL学习-idea连接数据库导入jar包

    导包先有包 !!!一定要下载和自己MySQL版本一样的jar包!!! !!!一定要下载和自己MySQL版本一样的jar包!!! !!!一定要下载和自己MySQL版本一样的jar包!…

    技术杂谈 2023年6月21日
    0108
  • 文档分享-Activiti 5.16 用户手册

    今天在翻看工作流相关的网页的时候,在开源中国上http://www.oschina.net/question/915507_149175发现activiti的中文文档:http:/…

    技术杂谈 2023年6月1日
    0110
  • 【考研】C语言

    考研C语言 收录数据结构会用到的C语言知识,建议有基础的情况下再学习,针对性学习即可。 往后的学习要多从内存角度去学习计算机的知识 1. 数组 1.1 一维数值数组 具备相同的数据…

    技术杂谈 2023年7月10日
    085
  • FFMPEG 配置选项详细说明

    转自:https://blog.csdn.net/z2066411585/article/details/81239446 用法:配置[选项]选项:[描述后括号中的默认值] 帮助选…

    技术杂谈 2023年6月1日
    077
  • C++11实现的数据库连接池

    它什么是? 数据库连接池负责分配、管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个;类似的还有线程池。 为什么要用? 一个数据库连接对象均对应…

    技术杂谈 2023年7月24日
    088
  • Python基本语法学习

    CSN Python学习作业 Python的变量不需要声明,但每个变量在使用前都必须赋值。在Python中,变量就是变量,它没有所谓的”类型”一说 Pyth…

    技术杂谈 2023年7月11日
    075
  • selenium工作原理

    博客园 :当前访问的博文已被密码保护 请输入阅读密码: Original: https://www.cnblogs.com/111testing/p/15723648.htmlAu…

    技术杂谈 2023年5月31日
    097
  • Golang仿云盘项目-2.1基础版文件上传

    目录结构 E:\goproj\FileStorageDisk │ main.go │ readme.txt │ ├─handler │ handler.go │ └─static …

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