思路:

设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. Python爬虫之多线程

    详情点我跳转 关注公众号"轻松学编程"了解更多. 多线程 在介绍Python中的线程之前,先明确一个问题,Python中的多线程是假的多线程! 为什么这么说,我们先明确一个概念,全 ...

  2. SpringBoot中的classpath

    一句话总结:classpath 等价于 main/java + main/resources + 第三方jar包的根目录.下面详细解释. 首先,classpath顾名思义,是编译之后项目的路径,而不是 ...

  3. setTimeout、同步、异步的理解

    console.log('111'); setTimeout(()=>{ console.log('222') },1000); console.log('333'); setTimeout(( ...

  4. 力扣 - 768. 最多能完成排序的块II

    目录 题目 思路 代码实现 复杂度分析 题目 这个问题和"最多能完成排序的块"相似,但给定数组中的元素可以重复,输入数组最大长度为2000,其中的元素最大为10**8. arr是一 ...

  5. Python列表排序方法汇总,超详细!

    1. 修改原列表,不创建新列表的排序 1 a = [3, 2, 8, 4, 6] 2 print(id(a)) # 2180873605704 3 a.sort() # 默认升序 4 print(a) ...

  6. C\C++语言重点——指针篇 | 为什么指针被誉为 C 语言灵魂?(一文让你完全搞懂指针)

    本篇文章来自小北学长的公众号,仅做学习使用,部分内容做了适当理解性修改和添加了博主的个人经历. 注:这篇文章好好看完一定会让你掌握好指针的本质! 看到标题有没有想到什么? 是的,这一篇的文章主题是「指 ...

  7. tp3.2自动验证

    <?php namespace Home\Model; use Think\Model; class UserModel extends Model{ protected $patchValid ...

  8. Docker + Jenkins + Gitlab + Pytest + Allure 接口自动化测试之持续集成实战终极教程

    实战教程篇 前言 这边就不教大家怎么用 pytest 写项目了哦,下面有系列文章能帮助你快速入门 Pytest + Allure 这一篇教程主要是教如何从 0 到 1 搭建自动化测试的持续集成环境 后 ...

  9. uboot分析——makefile

    1.makefile分析 $(TOPDIR)/makefile | |-----> include $(obj)/include/config.mk  确定板子环境 | || | V |---- ...

  10. ceph各个版本之间参数变化分析

    前言 本篇主要是分析ceph的版本之间参数的变化,参数变化意味着功能的变化,通过参数来分析增加,删除,修改了哪些功能,以及版本之间的变化,本篇主要通过导出参数,然后通过脚本去比对不同的版本的参数变化 ...