求条
  • 板块灌水区
  • 楼主Rolen
  • 当前回复2
  • 已保存回复3
  • 发布时间2024/8/15 16:40
  • 上次更新2024/8/15 18:48:03
查看原帖
求条
730113
Rolen楼主2024/8/15 16:40

P10468 兔子与兔子

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=212370440130137957ll;
string s;
ll len,q,l1,l2,r1,r2,p[2000005];
ll h[2000005];
ll haash(ll l,ll r){
	return (h[r]-((h[l-1]*p[r-l+1])%mod)+mod)%mod;
}
int main(){
	cin>>s;
	len=s.length();
	p[0]=1;
	for(int i=1;i<=len;i++){
		p[i]=(p[i-1]*231)%mod;
	}
	for(int i=0;i<len;i++){
		h[i+1]=(((h[i]*231)%mod)+s[i]-'a'+1+mod)%mod;
	}
	cin>>q;
	while(q--){
		cin>>l1>>r1>>l2>>r2;
		if(haash(l1,r1)==haash(l2,r2)){
			cout<<"Yes\n";
		}
		else
		cout<<"No\n";
	}
}

不知道为什么wa了

2024/8/15 16:40
加载中...