用哈希怎么wa了
查看原帖
用哈希怎么wa了
1043214
pyxx_楼主2023/11/28 20:57
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int P=131;
ull hs[1005],ht[1005],p[1005];
ull get_hs(int l,int r){
	return hs[r]-hs[l-1]*p[r-l+1];
}
ull get_ht(int l,int r){
	return ht[r]-ht[l-1]*p[r-l+1];
}
int main(){
	string s,t;
	s='0';
	t='0';
	string a,b;
	cin>>a>>b;
	s=s+a;t=t+b;
	int q;
	cin>>q;
	//预处理两个字符串
	int lens=s.length();
	int lent=t.length();
	p[0]=1,hs[0]=0,ht[0]=0;
	for(int i=1;i<=lens;i++){
		p[i]=p[i-1]*P;
		hs[i]=hs[i-1]*P+s[i];
	}
	for(int i=1;i<=lent;i++){
		ht[i]=ht[i-1]*P+t[i];
	}
	while(q--){
		int l1,r1,l2,r2;
		cin>>l1>>r1>>l2>>r2;
		ull x=get_hs(l1,r1);
		ull y=get_ht(l2,r2);
		if(x==y)cout<<"ovo"<<endl;
		else if(x>y)cout<<"erfusuer"<<endl;
		else cout<<"yifusuyi"<<endl;
	}
	return 0;
}

2023/11/28 20:57
加载中...