2 solutions

  • 0
    @ 2025-3-4 19:49:13

    #include<bits/stdc++.h> using namespace std; const int N=1e7; int main() { unordered_map<int,string>p; int i,n,m,l1,r1,l2,r2; char s; cin>>n>>m; for(i=0;i<n;i++){ cin>>s; p[i+1]=s; } while(m--) { cin>>l1>>r1>>l2>>r2; string s1,s2; for(i=l1;i<=r1;i++){ s1+=p[i]; } for(i=l2;i<=r2;i++){ s2+=p[i]; } if(s1==s2){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } return 0; }

    • 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
      34
      Accepted
      7
      Uploaded By