链接
分析
要保持子串的有序性,那我们可以想象向子串左右边找,判断是否找到相同的字符就可以了。数据很小,直接遍历。
代码
#include <iostream>
#include <string>
#include <cstdio>
int t, n, q, l, r;
using namespace std;
int main() {
cin >> t;
while (t--){
cin >> n >> q;
char s[100];
scanf("%s", s);
for (int i = 0; i < q; ++i) {
cin >> l >> r;
bool flag = false;
for (int j = 0; j < l - 1; ++j)
if (s[j] == s[l - 1]) flag = true;
for (int j = r; j < n; ++j)
if (s[j] == s[r - 1]) flag = true;
printf("%s\n", flag ? "YES":"No");
}
}
return 0;
}