跳到正文

个人记录

p10468

zlqwq约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年8月3日
收录
2025年12月12日
更新
2026年11月6日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>

#define int long long

using namespace std;

int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			f=-f;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
string s;
int h1[1000005],h2[1000005];
int pow1[1000005],pow2[1000005];
const int base1=233;
const int base2=13;
const int mod1=1e9+7;
const int mod2=998244353;
int query(int l,int r){
	return (h1[r]-h1[l-1]*pow1[r-l+1])%mod1;
}
int qr(int l,int r){
	return (h2[r]-h2[l-1]*pow2[r-l+1])%mod2;
}
signed main(){
	cin>>s;
	int n=s.size();
	s=" "+s;
	pow1[0]=pow2[0]=1;
	for(int i=1;i<=n;i++){
		h1[i]=(h1[i-1]*base1+s[i]-'0')%mod1;
		h2[i]=(h2[i-1]*base2+s[i]-'0')%mod2;
		pow1[i]=(pow1[i-1]*base1)%mod1;
		pow2[i]=(pow2[i-1]*base2)%mod2;
	}
	int Q=read();
	while(Q--){
		int l=read(),r=read(),L=read(),R=read();
		if(query(l,r)==query(L,R)&&qr(l,r)==qr(L,R)){
			cout<<"Yes\n";
		}
		else{
			cout<<"No\n";
		}
	}
	return 0;
}
原文