Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define pf push_front
- #define f first
- #define s second
- using namespace std;
- const int MAXN = 1e6 + 10;
- const int MOD = 1e9 + 7;
- ll hhash[MAXN], st[MAXN];
- ll get(int l, int r, int n) {
- return ((((hhash[r] - hhash[l - 1] + MOD) % MOD) * st[n - l]) % MOD);
- }
- int p = 43;
- int main() {
- string s;
- cin >> s;
- st[0] = 1;
- int n = s.size();
- for(int i = 1; i <= n; i++) {
- st[i] = (st[i - 1] * p) % MOD;
- }
- s = '!' + s;
- for(int i = 1; i <= n; i++) {
- hhash[i] = (hhash[i - 1] + (s[i] - 'a' + 1) * st[i]) % MOD;
- }
- int q;
- cin >> q;
- while (q--) {
- int l1, r1, l2, r2;
- cin >> l1 >> r1 >> l2 >> r2;
- if (get(l1, r1, n) == get(l2, r2, n)) cout << "Yes" << endl;
- else cout << "No" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment