思路:

设tx为t类别字符的个数。

①对于长度小于2的t明显是"YES"
②对于字符类别只有1个的t明显是"YES"
③对于字符类别有2个的t,如左上图:如果str[l] != str[r],那么我们构造的t也应该是str[l] != str[r],且s字串和t的str[l]和str[r]是相反的,即如图所示。继续,如图构造,即bbb..a...a这样,我们发现第一个图片除去str[l] = a和str[r]=b之外,中间怎么放置字符,都会出现"Irreducible Anagrams"的情况,所以"YES"。
④对于字符类别有2个的t,如果str[l] == str[r],如右边的图,总有k = 2,让s1包含一个a和bx个b,使得"reducible Anagrams"存在,所以"NO"。
④对于字符类别有3个的t,按着左上的图也无法构造出"Irreducible Anagrams" 情况,说明字符类别为3的t,不论说明字符排列都存在"reducible Anagrams",所以"NO"。
⑤对于字符类别大于3个的t,由④推出是"NO"。

 1 #include <iostream>
2 #include <cstdio>
3 #include <algorithm>
4 #include <cstring>
5 using namespace std;
6
7 const int N = 2e5 + 10;
8 int dp[30][N];
9 char str[N];
10
11 void solve()
12 {
13 scanf("%s", str);
14 int n = strlen(str);
15 /// cout << "n = " << n << endl;
16 for(int i = 1; i <= n; ++i) {
17 dp[str[i - 1] - 'a'][i]++;
18 /// cout << dp[str[i - 1] - 'a'][i] << endl;
19 for(int c = 0; c < 26; ++c) {
20 dp[c][i] += dp[c][i - 1];
21 }
22 }
23 /*
24 for(int c = 0; c < 26; ++c) {
25 printf("%c :\n", 'a' + c);
26 for(int i = 1; i <= n; ++i) {
27 printf("%d ", dp[c][i]);
28 }
29 printf("\n");
30 }
31 */
32 int q;
33 scanf("%d", &q);
34 vector<pair<int ,int > > vp;
35 for(int i = 0; i < q; ++i) {
36 int l, r;
37 scanf("%d%d", &l, &r);
38 vp.push_back(make_pair(l, r));
39 }
40
41 ///vector<int > ans;
42 for(auto info : vp) {
43 int l = info.first;
44 int r = info.second;
45
46 int kinds = 0;
47 int sum = 0;
48 for(int c = 0; c < 26; ++c) {
49 kinds += (dp[c][r] - dp[c][l - 1]) > 0;
50 sum += dp[c][r] - dp[c][l - 1];
51 }
52 ///cout << "tot = " << kinds << endl;
53 if(sum == 1 || (kinds == 2 && str[l - 1] != str[r - 1]) || kinds > 2) {
54 printf("YES\n");
55 } else printf("NO\n");
56 }
57
58 }
59
60 int main()
61 {
62 solve();
63
64 return 0;
65 }

B. Irreducible Anagrams【CF 1290B】的更多相关文章

  1. 【CF#338D】GCD Table

    [题目描述] 有一张N,M<=10^12的表格,i行j列的元素是gcd(i,j) 读入一个长度不超过10^4,元素不超过10^12的序列a[1..k],问是否在某一行中出现过 [题解] 要保证g ...

  2. 【CF#303D】Rotatable Number

    [题目描述] Bike是一位机智的少年,非常喜欢数学.他受到142857的启发,发明了一种叫做“循环数”的数. 如你所见,142857是一个神奇的数字,因为它的所有循环排列能由它乘以1,2,...,6 ...

  3. 【CF 463F】Escape Through Leaf

    题意 给你一棵 \(n\) 个点的树,每个节点有两个权值 \(a_i,b_i\). 从一个点 \(u\) 可以跳到以其为根的子树内的任意一点 \(v\)(不能跳到 \(u\) 自己),代价是 \(a_ ...

  4. 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

    A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...

  5. 【CF 585E】 E. Present for Vitalik the Philatelist

    E. Present for Vitalik the Philatelist time limit per test 5 seconds memory limit per test 256 megab ...

  6. 【35.20%】【CF 706D】Vasiliy's Multiset

    time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. 【26.8%】【CF 46D】Parking Lot

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. 【31.42%】【CF 714A】Meeting of Old Friends

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  9. 【31.95%】【CF 714B】Filya and Homework

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

随机推荐

  1. Scrapy加Redis加IP代理池实现音乐爬虫

    音乐爬虫 关注公众号"轻松学编程"了解更多. 目的:爬取歌名,歌手,歌词,歌曲url. 一.创建爬虫项目 创建一个文件夹,进入文件夹,打开cmd窗口,输入: scrapy star ...

  2. Python+Selenium(1)- 环境搭建

    一,Selenium 简介 Selenium是目前最流行的web自动化测试工具,也常用于网络爬虫,已经更新到3以上的版本. 1,组件 它提供了以下web自动化测试组件: Selenium IDE,Fi ...

  3. Android测试三件套:传文件、抓包、看日志

    在对安卓进行测试时,我们需要把 apk 传到安卓机上,对请求抓包,同时监控应用日志.本文就来讲讲具体操作. 安卓机是指基于安卓的机器 ,如手机.POS 机.电视盒子等. 传文件 我们拒绝用 U 盘传文 ...

  4. layui tempalte添加函数

    @*超链接action展示*@ <script type="text/html" id="ShowAction"> {{# if(d.DealSta ...

  5. ixgbe 驱动 为xxx驱动做准备1

    网卡都是pci设备,因此这里每个网卡驱动其实就是一个pci驱动.并且intel这里是把好几个万兆网卡(82599/82598/x540)的驱动做在一起的.V4L2 一样几个类型摄像头合并在一起 先说一 ...

  6. 利用c++ std::getline实现split

    getline reads characters from an input stream and places them into a string: getline从输入流中读取字符, 并把它们转 ...

  7. 为什么关不掉所有的OSD

    前言 碰到一个cepher问了一个问题: 为什么我的OSD关闭到最后有92个OSD无法关闭,总共的OSD有300个左右 想起来在很久以前帮人处理过一次问题,当时环境是遇上了一个BUG,需要升级到新版本 ...

  8. [LeetCode题解]141. 环形链表 | 快慢指针

    题目描述 给定一个链表,判断链表中是否有环. 如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的 ...

  9. 两种不同的扩展Scrum的方式

    两种不同的扩展Scrum的方式 1.LeSS和LeSS Huge –大型Scrum LeSS(和LeSS Huge –真正的大型程序)的合著者Craig Larman首先批评了管理,开发人员和客户传统 ...

  10. 精尽 MyBatis 源码分析 - MyBatis 初始化(一)之加载 mybatis-config.xml

    该系列文档是本人在学习 Mybatis 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释(Mybatis源码分析 GitHub 地址.Mybatis-Spring 源码分析 GitHub ...