兔子与兔子

#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
//const ll P=1e9+7;
const ull base=131;     //挺好用的一个hash base 
const int N=1e6+10;
int m;
ull sum[N],powe[N];
char s[N];

int main()
{
    scanf( "%s",s+1 );

    powe[0]=1; int len=strlen(s+1);
    for ( int i=1; i<=len; i++ )
    {
        //sum[i]=(sum[i-1]*base+(s[i]-'a'+1))%P;
        sum[i]=(sum[i-1]*base+(s[i]-'a'+1));        //字符串hash前缀和 
        powe[i]=powe[i-1]*base;                 //其实可以把字符串hash理解为base进制数 
        //powe[i]=powe[i-1]*base%P;
    }

    scanf( "%d",&m );
    while ( m-- )
    {
        int l1,l2,r1,r2; scanf( "%d%d%d%d",&l1,&r1,&l2,&r2 );
        //ll res1=sum[r1]-sum[l1-1]*powe[r1-l1+1]%P;
        ull res1=sum[r1]-sum[l1-1]*powe[r1-l1+1];
        ull res2=sum[r2]-sum[l2-1]*powe[r2-l2+1];
        //ll res2=sum[r2]-sum[l2-1]*powe[r2-l2+1]%P;
        if ( res1==res2 ) printf( "Yes\n" );
        else printf( "No\n" );
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值