-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path685A.cpp
More file actions
53 lines (51 loc) · 1.17 KB
/
Copy path685A.cpp
File metadata and controls
53 lines (51 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, m;
scanf("%d %d", &n, &m);
string s;
cin >> s;
while (m--)
{
int u, v;
scanf("%d %d", &u, &v);
string s1;
for (int i = u-1; i < v; i++)
{
s1.push_back(s[i]);
}
int cnt = 0;
int k = 0;
bool yes = false;
if(s1.size()==1){
printf("NO\n");
continue;
}
for (int i = 0; i < s.size(); i++)
{
if(s[i]==s1[k] && cnt < s1.size()-1){
k++;
cnt++;
if(k >= s1.size()){
yes = true;
break;
}
}
else if(s[i]!=s1[k] || cnt == s1.size()-1){
cnt = 0;
}
}
if(yes){
printf("YES\n");
}
else{
printf("NO\n");
}
}
}
}