1 solutions

  • 0
    @ 2022-8-16 20:32:03

    自然溢出

    #include <bits/stdc++.h>
    using namespace std;
    #define accelerate ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define int unsigned long long
    #define mod 1000000007
    #define ll unsigned long long
    #define PII pair<int,int>
    #define INF 0x3f3f3f3f
    const int N=1e5+10;
    const int base=29;
    int n,m,k,x,y,T,xx,yy;
    int hashh[N],p[N];
    char a[N];
    int getnum(int x,int y){
    	return hashh[y]-hashh[x-1]*p[y-x+1];
    }
    signed main(){
    	accelerate;
    	cin>>n>>m;
    	cin>>a+1;
    	p[0]=1;
    	for(int i=1;i<=n;i++){
    		p[i]=p[i-1]*base;
    		hashh[i]=hashh[i-1]*base+(a[i]-'a'+1);
    	}
    	while(m--){
    		cin>>x>>y>>xx>>yy;
    		if(getnum(x,y)==getnum(xx,yy)) cout<<"Yes\n";
    		else cout<<"No\n";
    	}
    	return 0;
    } 
    
    • 1

    Information

    ID
    6530
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    8
    Tags
    # Submissions
    19
    Accepted
    5
    Uploaded By