Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define FAST_ALLOCATOR_MEMORY 1e8
- #include "optimization.h"
- #include <bits/stdc++.h>
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef double dd;
- typedef vector<ll> vi;
- typedef vector<vector<ll>> vvi;
- typedef vector<ll> vll;
- typedef vector<vector<ll>> vvl;
- typedef vector<pair<ll, ll>> vpii;
- typedef pair<ll, ll> pii;
- typedef vector<pair<ll, ll>> vpll;
- typedef pair<ll, ll> pll;
- #define mp make_pair
- #define pb push_back
- #define ff first
- #define ss second
- #define all(c) (c).begin(), (c).end()
- #define MOD 1000000007
- #define INF 999999999999999999
- const int p = 29;
- string s;
- vll power;
- vll arr;
- ll precalc(){
- int sz = s.size();
- power[0] = 1;
- for(ll i = 1; i < sz; i++) {
- power[i] = (power[i - 1] * p) % MOD;
- }
- for(int i = 0; i < sz; i++) {
- arr[i] = (s[i] - 'a' + 1) * power[i];
- arr[i] %= MOD;
- if (i) {
- arr[i] += arr[i - 1];
- arr[i] %= MOD;
- }
- }
- }
- int main() {
- #ifdef HOME
- freopen("kek.in", "r", stdin);
- freopen("kek.out", "w", stdout);
- #endif
- char st[100000 + 5];
- readWord(st);
- s = string(st);
- power.resize(s.size(), 0);
- arr.resize(s.size(), 0);
- power[0] = 1;
- precalc();
- int n, a, b, c, d;
- n = readInt();
- for(int i = 0; i < n; i++){
- a = readInt() - 1;
- b = readInt() - 1;
- c = readInt() - 1;
- d = readInt() - 1;
- if(b - a != d - c) {
- writeWord("No\n");
- continue;
- }
- if(a == c && b == d){
- writeWord("Yes\n");
- continue;
- }
- ll len = b - a + 1;
- ll h1 = arr[a + len - 1];
- if(a){
- h1 = (h1 - arr[a - 1] + MOD) % MOD;
- }
- ll h2 = arr[c + len - 1];
- if(c){
- h2 = (h2 - arr[c - 1] + MOD) % MOD;
- }
- if((a < c && (h1 * power[c - a]) % MOD == h2) || (a > c && h1 == (h2 * power[a - c]) % MOD)) {
- writeWord("Yes\n");
- }
- else {
- writeWord("No\n");
- }
- }
- // for(auto a : arr)
- // cout << a << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement