#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pw(x) (1ll << x)
#define sz(x) (int)((x).size())
#define pb push_back
#define endl '\n'
#define mp make_pair
#define vec vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef unsigned long long ull;
typedef unsigned int uint;
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T>
using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
inline void solve () {
string s; cin >> s;
int n = sz(s);
vector <vector <int>> pref (n, vector <int> (26));
for (int i = 0; i < n; ++i) {
++pref[i][s[i] - 'a'];
if (!i) continue;
for (int j = 0; j < 26; ++j) {
pref[i][j] += pref[i - 1][j];
}
}
auto get = [&] (int i, int l, int r) { return pref[r][i] - (l ? pref[l - 1][i] : 0); };
int q; cin >> q;
while (q--) {
int l, r, L, R; cin >> l >> r >> L >> R; --l, --r, --L, --R;
if (r - l == R - L) {
bool ok = 1;
for (int j = 0; j < 26; ++j) ok &= (get(j, l, r) == get(j, L, R));
cout << (ok ? "DA" : "NE") << endl;
}
else {
cout << "NE" << endl;
}
}
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1; // cin >> t;
while (t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
472 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
29 ms |
8288 KB |
Output is correct |
7 |
Correct |
26 ms |
8196 KB |
Output is correct |
8 |
Correct |
26 ms |
8244 KB |
Output is correct |
9 |
Correct |
26 ms |
8268 KB |
Output is correct |
10 |
Correct |
26 ms |
8248 KB |
Output is correct |