思路:

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

    我是风筝,公众号「古时的风筝」,一个兼具深度与广度的程序员鼓励师,一个本打算写诗却写起了代码的田园码农! 文章会收录在 JavaNewBee 中,更有 Java 后端知识图谱,从小白到大牛要走的路都在 ...

  2. Blazor 准备好为企业服务了吗?

    如果您正在编写 .NET Web 应用程序,您很可能已经意识最近一年在.NET Web开发领域的热点都是 Blazor 的.如果你还没有了解Blazor,它允许您使用 C# 来编写 Web UIs,传 ...

  3. OGG投递进程报错无法open文件,无法正常投递

    1.1现象 之前有个客户遇到一个问题,OGG同步数据链路,突然有一天网络出现问题,导致OGG投递进程无法正常投递,无法写入目标端的该文件. 猜测是由于网络丢包等原因导致文件损坏,无法正常open,re ...

  4. layui导航

    关于导航 首先看一下官网的样式: <!DOCTYPE html><html><head> <meta charset="utf-8" /& ...

  5. Linux C 获取本机所有网卡的 IP,Mask

    0 运行环境 本机系统:Windows 10 虚拟机软件:Oracle VM VirtualBox 6 虚拟机系统:Ubuntu 18 1 代码 #include <sys/ioctl.h> ...

  6. python类继承中构造子的调用

    python面向对象中的继承关系中,子类对父类的构造方法的调用有两种方法: 父类名.__init__(self,参数) #注意名字是父类 super(本子类名,self)__init__(其他参数) ...

  7. GDT,LDT,GDTR,LDTR (转 侵删)

    一.引入 保护模式下的段寄存器 由 16位的选择器 与 64位的段描述符寄存器 构成 段描述符寄存器: 存储段描述符 选择器:存储段描述符的索引 段寄存器(16位选择子,64为隐藏信息) 原先实模式下 ...

  8. cetos6.5 gcc4.8 安装

    1.准备源 #安装仓库 wget http://people.centos.org/tru/devtools-2/devtools-2.repo mv devtools-2.repo /etc/yum ...

  9. Angualr 内置工具-SelectionModel

    SelectionModel: 被用来控制选中一个和多个item时候的逻辑.例如下拉菜单,复选框选中等,非常方便. 引入:import{SelectionModel}from'@angular/cdk ...

  10. USACO 2020 OPEN Favorite Colors【并查集-启发式合并-思考】

    题目链接 题意简述 仰慕喜欢同色奶牛的奶牛喜欢同色 (禁止套娃 ,求一种方案,奶牛喜欢的颜色种数最多,多种方案求字典序最小. 题目解析 这道题我最先想到的居然是二分+并查集,我在想啥 咳咳 首先,考虑 ...