#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define OYY 100000005
#define mod 100000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid (start+end)/2
#define lim 500005
int pre[30][lim];
int32_t main(){
faster
string s;cin>>s;
// s="+"+s;
int n=s.length();
for(int i=0;i<n;i++){
pre[s[i]-'a'][i]++;
for(int j=0;j<28;j++){
if(i!=0)pre[j][i]+=pre[j][i-1];
}
}
//cout<<"j"<<endl;
int q;cin>>q;
while(q--){
int a,b,c,d;
cin>>a>>b>>c>>d;
a--;b--;c--;d--;
if(b-a!=d-c){
cout<<"NE"<<'\n';
continue;
}
bool stop=true;
for(int i=0;i<28;i++){
int da,dc;
if(a-1<0)da=0;
else da=pre[i][a-1];
if(c-1<0)dc=0;
else dc=pre[i][c-1];
if(pre[i][b]-da!=pre[i][d]-dc){
stop=false;
break;
}
}
if(stop){
cout<<"DA"<<'\n';
}
else cout<<"NE"<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
23 ms |
25436 KB |
Output is correct |
7 |
Correct |
28 ms |
26944 KB |
Output is correct |
8 |
Correct |
23 ms |
26972 KB |
Output is correct |
9 |
Correct |
23 ms |
27124 KB |
Output is correct |
10 |
Correct |
22 ms |
27124 KB |
Output is correct |