#include <bits/stdc++.h>
using namespace std;
// Macros
#define int long long
// #define double long long double
#define pb push_back
#define str string
#define vi vector<int>
#define mp make_pair
#define mi map<int, int>
#define umi unordered_map<int, int>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define all(a) a.begin(), a.end()
#define endl "\n"
int mod = 1000000007;
int INF = 1e18;
template<typename T>
void printMap(T a){
cout << "{ ";
for (auto x: a){
cout << x.first << ": " << x.second << " ";
}
cout << "}" << endl;
}
int min_element(vi a){
int m = 10000000000000;
for (auto x: a){
m = min(m, x);
}
return m;
}
void printVector(vi a){
for (auto x: a){
cout << x << " ";
}
cout << endl;
}
int max_element(vi a){
int m = -1e17;
for (auto x: a){
m = max(m, x);
}
return m;
}
int max(int x, int y){
if (x > y) return x;
else return y;
}
int min(int x, int y){
if (x < y) return x;
else return y;
}
void solve(){
string inp; cin >> inp;
int n = inp.size();
vector<int> a(n);
FOR(i,0,inp.size()){
a[i] = inp[i]-'a'+1;
}
int count[27][n];
int prefix[27][n];
FOR(i,0,27){
FOR(j,0,n){
count[i][j] = 0;
}
}
FOR(i,0,n){
count[a[i]][i] = 1;
}
FOR(i,1,27){
prefix[i][0] = count[i][0];
FOR(j,1,n) prefix[i][j] = count[i][j]+prefix[i][j-1];
}
int q; cin >> q;
while (q--){
int l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2;
l1--;r1--;l2--;r2--;
int can = true;
FOR(i,1,27){
int count = prefix[i][r1];
if (l1) count -= prefix[i][l1-1];
int count2 = prefix[i][r2];
if (l2) count2 -= prefix[i][l2-1];
if (count != count2) can = false;
// cout << count << count2 << endl;
}
if (can) cout << "DA" << endl;
else cout << "NE" << endl;
}
}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(0);
// int t; cin >> t;
int t = 1;
for (int tc = 1; tc <= t; tc++){
// cout << "Case #" << tc << ": ";
solve();
}
}
Compilation message
programiranje.cpp: In function 'void solve()':
programiranje.cpp:13:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
| ^
programiranje.cpp:64:5: note: in expansion of macro 'FOR'
64 | FOR(i,0,inp.size()){
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
712 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
38 ms |
23104 KB |
Output is correct |
7 |
Correct |
43 ms |
23188 KB |
Output is correct |
8 |
Correct |
45 ms |
23116 KB |
Output is correct |
9 |
Correct |
51 ms |
23204 KB |
Output is correct |
10 |
Correct |
39 ms |
23220 KB |
Output is correct |