AcWing 841. 字符串哈希(模板)
程序员文章站
2022-04-24 12:46:06
...
题目链接:点击这里
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
const int N = 100010, base = 131;
int n, m;
char str[N];
ull h[N], p[N];
ull get(int l, int r)
{
return h[r] - h[l - 1] * p[r -l + 1];
}
int main()
{
scanf("%d%d%s", &n, &m, str + 1);
p[0] = 1;
for(int i = 1; i <= n; ++i)
{
h[i] = h[i - 1] * base + str[i];
p[i] = p[i - 1] * base;
}
while(m--)
{
int l1, r1, l2, r2;
scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
if(get(l1,r1)==get(l2,r2)) puts("Yes");
else puts("No");
}
return 0;
}
上一篇: 护眼麦芒5带你健康跨年!