字符串哈希

没有模的版本


const int N = 1000010 ;
const int m = 131 ;
const int mod = 1e9 + 7 ; 

int n, T ;
char s[N] ;
int f[N], p[N] ;

int main() {
	scanf("%s", s + 1) ; n = strlen(s + 1) ;
	p[0] = 1 ;
	for (int i = 1; i <= n; i++) {
		f[i] = f[i - 1] * m + s[i] - 'a' + 1 ;
		p[i] = p[i - 1] * m;
	}
	scanf("%d", &T) ;
	while (T--) {
		int a, b, c, d ; scanf("%d%d%d%d", &a, &b, &c, &d) ;
		if (f[b] - f[a - 1] * p[b - a + 1] == f[d] - f[c - 1] * p[d - c + 1]) puts("Yes") ;
		else puts("No") ; 
	}
}
posted @ 2023-08-11 17:34  哈奇莱特  阅读(13)  评论(0)    收藏  举报