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

时间:2020-12-27 18:05:44   收藏:0   阅读:43

技术分享图片

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;
}

 

原文:https://www.cnblogs.com/xfldbk/p/14197829.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!