forked from Onlian0/FEFU_second_semester
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC4.cpp
More file actions
56 lines (52 loc) · 1.17 KB
/
C4.cpp
File metadata and controls
56 lines (52 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
54
55
56
#include <bits/stdc++.h>
using namespace std;
const int SIZE = str.size() + 1;
const int BASE = 2017;
const int MOD = 1000000009;
void init_powers(long long *p, int base, int mod, int SIZE)
{
p[0] = 1;
for (int i = 1; i < SIZE; ++i)
{
p[i] = p[i - 1] * base % mod;
}
}
// O(n)
void init_hash(const string &line, long long *h, int base, int mod)
{
h[0] = 0;
int n = line.size();
for (int i = 1; i <= n; ++i)
{
h[i] = h[i - 1] * base % mod + line[i - 1];
}
}
// const
long long get_hash(int l, int r, long long *h, long long *p, int mod)
{
return (h[r] - h[l] * p[r - l] % mod + mod) % mod;
}
int main()
{
string str;
cin >> str;
long long ahash[SIZE];
long long powers[SIZE];
init_powers(powers, BASE, MOD, SIZE);
init_hash(str, ahash, BASE, MOD);
int q;
cin >> q;
while (q--)
{
int a, b, c, d;
cin >> a >> b >> c >> d;
if (get_hash(a - 1, b, ahash, powers, MOD) == get_hash(c - 1, d, ahash, powers, MOD))
{
cout << "Yes\n";
}
else
{
cout << "No\n";
}
}
}