题解 CF1290B 【Irreducible Anagrams】
zhangyuzhe · · 个人记录
Describe
Irreducible Anagrams
Solution
神仙结论题
分类讨论:
-
-
-
- 其他情况则不成立。
处理一段区间的字符数可以用前缀和
Code
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int nn = 2e5 + 10;
string S;
int Q, N, Sum[nn][27];
int main () {
ios::sync_with_stdio(false);
cin >> S >> Q;
N = S.size(); S = " " + S;
for (int i = 1; i <= N; i ++) {
for (int j = 0; j < 26; j ++)
Sum[i][j] = Sum[i - 1][j] + ((S[i] - 'a') == j);
}
for (int i = 1; i <= Q; i ++) {
int L, R, TOT = 0;
cin >> L >> R;
for (int j = 0; j <= 25; j ++) TOT += ((Sum[R][j] - Sum[L - 1][j]) !=0);
if (L == R) cout << "Yes" << endl;
else if (S[L] != S[R]) cout << "Yes" << endl;
else if (TOT >= 3) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}