哈希.字符串哈希.AcWing.841

时间:2021-01-01 11:54:31   收藏:0   阅读:0

技术图片

code:

#include<bits/stdc++.h>//xfl
using namespace std;
const int N = 100007;
typedef unsigned long long ull;
ull mis[N],sum[N];
string s;
int n,m,l1,l2,r1,r2;
int main()
{
    cin>>n>>m>>s;
    mi[0]=1;
    for(int i=1;i<=n;++i)
    {
        mi[i]=mi[i-1]*131;
        sun[i]=sum[i-1]*131+s[i-1];
    }
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
        int l=r1-l1+1;
        ull h1=sum[r1]-sum[l1-1]*mi[l];
        ull h2=sum[r2]-sum[l2-1]*mi[l];
        if(h1==h2)puts("Yes");
        else puts("No");
    }
    return 0;
}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!