Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- //typedef int ll;
- typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- ll MAX = 1e15;
- vector<ll> hashes;
- vector<ll> pows;
- //resent
- int main() {
- ios_base::sync_with_stdio(0);
- freopen("substrcmp.in", "r", stdin);
- freopen("substrcmp.out", "w", stdout);
- string s;
- cin >> s;
- ll n = s.size();
- hashes.resize(n);
- pows.resize(n+1);
- ll p = 31;
- pows[0]=1;
- for(ll i=1; i<=n; i++){
- pows[i]=pows[i-1]*p;
- }
- hashes[0]=s[0];
- for(ll i=1; i<n; i++){
- hashes[i] = hashes[i-1]+s[i]*pows[i];
- }
- ll q;
- cin >> q;
- while(q--){
- ll a,b,c,d;
- cin >> a >> b >> c >> d;
- a--;
- b--;
- c--;
- d--;
- ll hash1, hash2 = 0;
- if(a==0){
- hash1 = hashes[b];
- }
- else {
- hash1 = hashes[b]-hashes[a-1];
- }
- if(c==0){
- hash2 = hashes[d];
- }
- else {
- hash2 = hashes[d]-hashes[c-1];
- }
- hash1 = hash1 * pows[n-a];
- hash2 *= pows[n-c];
- if(hash1==hash2){
- cout << "Yes\n";
- }
- else{
- cout << "No\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement