思路:

设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. MySQL连接报错(错误:1130)

    1. 原因 显示这个错误是因为没有连接到该机器MySQL数据库的权限,这是在一开始安装MySQL是默认设置的. 在数据库mysql下有一张名为`user`的表,其中的字段user下的root的值默认为 ...

  2. 关于appium

    一.特点 1.appium是开源的移动端自动化测试框架: 2.appium可以测试原生的.混合的.以及移动端的web项目: "移动原生应用"是指那些用iOS或者 Android S ...

  3. Centos中部署NetCore项目(二)

    前言 在centos中部署程序,一般都不会是使用控制台进程直接启动,或者是后台运行.而是一些守护进程管理工具进行管理,例如supervisor. 部署Web相关程序,使用nginx是比较普遍的, 安装 ...

  4. SpringCloud之Gateway

    一.为什么选择SpringCloud Gateway而不是Zuul? Gateway和Zuul的职责一样,都承担着请求分发,类似Nginx分发到后端服务器. 1.SpingCloud Gateway ...

  5. 深入web workers (上)

    前段时间,为了优化某个有点复杂的功能,我采用了shared workers + indexDB,构建了一个高性能的多页面共享的服务.由于是第一次真正意义上的运用workers,比以前单纯的学习有更多体 ...

  6. 关于C语言中的位运算符的学习即应用

    一.运算符的种类和运算规则: &      与:全1则1,有0则0   |       或:有1则1,全0则0   ^   异或:相同为0,不同为1   ~   取反:~是一元运算符,用来对一 ...

  7. STM32最小系统板OLED贪吃蛇

    上次用STM32F103最小系统板做了一个简单的OLED贪吃蛇小游戏,以下为游戏效果动图: 主要实现内容包括:贪吃蛇移动.方向控制.食物生成.分数处理.死亡判定. 这次想把自己的制作思路分享给大家,不 ...

  8. Flink基础:实时处理管道与ETL

    ​ 往期推荐: Flink基础:入门介绍 Flink基础:DataStream API Flink深入浅出:资源管理 Flink深入浅出:部署模式 Flink深入浅出:内存模型 Flink深入浅出:J ...

  9. 【RabbitMQ-7】RabbitMQ—交换机标识符

    死信队列概念 死信队列(Dead Letter Exchange),死信交换器.当业务队列中的消息被拒绝或者过期或者超过队列的最大长度时,消息会被丢弃,但若是配置了死信队列,那么消息可以被重新发布到另 ...

  10. JS中的Array之方法(2)

    colors=['red','green','black','blue']; (1).  concat(element[|other array])  //联接数组 colors.concat('ye ...