From b94989caf03c3a59ee9caca748cd0facceb413be Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 24 Oct 2022 10:37:45 +0800 Subject: [PATCH] B - Irreducible Anagrams https://codeforces.com/contest/1290/submission/177710968 --- Codeforces/1290/B/B.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Codeforces/1290/B/B.cpp diff --git a/Codeforces/1290/B/B.cpp b/Codeforces/1290/B/B.cpp new file mode 100644 index 00000000..c2068bdc --- /dev/null +++ b/Codeforces/1290/B/B.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2e5 + 5; + +int n, a[N][26]; +std::string s; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> s >> n; + + s = ' ' + s; + + for (int i = 1; i < s.size(); i++) { + std::copy_n(a[i - 1], 26, a[i]); + + a[i][s[i] - 'a']++; + } + + for (int i = 1, l, r; i <= n; i++) { + cin >> l >> r; + + if (s[l] != s[r] || l == r) { + cout << "Yes" << endl; + + continue; + } + + int cnt = 0; + for (int i = 0; i < 26; i++) { + if (a[r][i] - a[l - 1][i] > 0) { + cnt++; + } + } + + cout << (cnt < 3 ? "No" : "Yes") << endl; + } + + return 0; +}