标签:ace span syn style color sign can long rgb
#include <bits/stdc++.h> typedef unsigned long long ll; const ll P=1331; using namespace std; ll hash1[1000000],u[1000000]; ll get(int l,int r){ return hash1[r]-hash1[l-1]*u[r-l+1]; } int main() { ios::sync_with_stdio(false); int n,m; cin>>n>>m; hash1[0]=1; u[0]=1; for(int i=1;i<=n;i++) u[i]=u[i-1]*P; char *s=new char[n+1]; scanf("%s",s+1); for(int i=1;i<=n;i++){ hash1[i]=hash1[i-1]*P+s[i]-‘a‘; } while(m--){ int l,r; cin>>l>>r; cout<<get(l,r)<<endl; } }
标签:ace span syn style color sign can long rgb
原文地址:https://www.cnblogs.com/qq1415584788/p/14706320.html