Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- int n;
- struct sct{
- int l,r;
- };
- void mk(sct &x){
- cin>>x.l>>x.r;
- x.l--;
- x.r--;
- }
- sct a,b;
- ll p = 29, mod = 1e9 + 7;
- vector <ll> hsh, pf, lvp;
- ll H(sct x){
- ll res;
- res = pf[x.r];
- ll k = x.r - x.l + 1;
- if (x.l > 0){
- res -= pf[x.l-1] * lvp[k] % mod;
- }
- if (res < 0) res += mod;
- return res;
- }
- ll nm(char x){
- return x - 'a' + 1;
- }
- void sh(sct x){
- cout<<x.l<<' '<<x.r<<"\n";
- }
- ll chk(ll x){
- if (x < 0){
- return x + mod;
- }
- return x;
- }
- В ЭТОЙ ЗАДАЧЕ СРАВНИВАЮТСЯ ПОДСТРОКИ
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string S; cin>>S;
- n = S.size();
- lvp.resize(n);
- hsh.resize(n);
- pf.resize(n);
- int t; cin>>t;
- lvp[0] = 1;
- for (int i = 1; i <n;++i){
- lvp[i] = lvp[i-1] * p % mod;
- }
- for (int i = 0; i < n;++i){
- hsh[i] = nm(S[i]) * lvp[n - i - 1] % mod;
- }
- pf[0] = nm(S[0]);
- for (int i = 1; i<n;++i){
- pf[i] = pf[i-1] * p % mod + nm(S[i]);
- pf[i] %= mod;
- }
- /*cout<<"lvp\n";
- cvl(lvp);
- cout<<"pf\n";
- cvl(pf);
- cout<<"hsh\n";
- cvl(hsh);*/
- for (int i = 0; i < t;++i){
- mk(a); mk(b);
- /*cout<<"a b\n";
- sh(a); sh(b);
- cout<<"H(a) = "<<H(a)<<"\n";
- cout<<"H(b) = "<<H(b)<<"\n";*/
- if (H(a) == H(b)){
- cout<<"Yes\n";
- }
- else{
- cout<<"No\n";
- }
- }
- }
- /*
- trololo
- 3
- 1 7 1 7
- 3 5 5 7
- 1 1 1 5
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement