转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove
#include<iostream> #include<cstdio> #include<map> #include<cstring> #include<cmath> #include<vector> #include<algorithm> #include<set> #include<stack> #include<string> #include<ctime> #include<queue> #include<cassert> #define inf 1000000005 #define M 10000005 #define N 110005 #define maxn 210005 #define eps 1e-8 #define zero(a) fabs(a)<eps #define Min(a,b) ((a)<(b)?(a):(b)) #define Max(a,b) ((a)>(b)?(a):(b)) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define mem(a,b) memset(a,b,sizeof(a)) #define LL long long #define MOD 1000000007 #define sqr(a) ((a)*(a)) #define Key_value ch[ch[root][1]][0] #define test puts("OK"); #define pi acos(-1.0) #define lowbit(x) ((-(x))&(x)) #define HASH1 1331 #define HASH2 10001 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; char str[1505]; char id[50]; int s[1505],k; LL fac1[N]={1},fac2[N]={1}; LL h1[N]={0},h2[N]={0}; LL get(int l,int r,LL *hash,LL *fac){ l++;r++; return hash[r]-hash[l-1]*fac[r-l+1]; } map<pair<LL,LL>,int>mpp; int main(){ for(int i=1;i<N;i++){ fac1[i]=fac1[i-1]*HASH1; fac2[i]=fac2[i-1]*HASH2; } cin>>str>>id>>k; int l=strlen(str); for(int i=1;i<=l;i++){ h1[i]=h1[i-1]*HASH1+str[i-1]; h2[i]=h2[i-1]*HASH2+str[i-1]; } for(int i=0;i<l;i++){ s[i]=1-(id[str[i]-'a']-'0'); } for(int i=1;i<l;i++) s[i]+=s[i-1]; int ans=0; for(int i=0;i<l;i++){ for(int j=i;j<l;j++){ if(s[j]-(i==0?0:s[i-1])<=k){ LL t1=get(i,j,h1,fac1),t2=get(i,j,h2,fac2); if(mpp.find(mp(t1,t2))==mpp.end()){ ans++; mpp[mp(t1,t2)]=1; } } } } cout<<ans<<endl; return 0; }
#include<iostream> #include<cstdio> #include<map> #include<cstring> #include<cmath> #include<vector> #include<algorithm> #include<set> #include<stack> #include<string> #include<ctime> #include<queue> #include<cassert> #define inf 1000000005 #define M 10000005 #define N 110005 #define maxn 210005 #define eps 1e-8 #define zero(a) fabs(a)<eps #define Min(a,b) ((a)<(b)?(a):(b)) #define Max(a,b) ((a)>(b)?(a):(b)) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define mem(a,b) memset(a,b,sizeof(a)) #define LL long long #define MOD 1000000007 #define sqr(a) ((a)*(a)) #define Key_value ch[ch[root][1]][0] #define test puts("OK"); #define pi acos(-1.0) #define lowbit(x) ((-(x))&(x)) #define HASH1 1331 #define HASH2 10001 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; int gcd(int a,int b){ return b==0?a:gcd(b,a%b); } int n,m; vector<int> fac; int main(){ cin>>n>>m; int t=0; for(int i=0;i<n;i++){ int num; cin>>num; t=gcd(num-1,t); } for(int i=1;i*i<=t;i++){ if(t%i==0){ fac.pb(i); if(i*i!=t) fac.pb(t/i); } } LL ans=0; for(int i=0;i<fac.size();i++){ int t=fac[i]; if(t&1){ for(int j=t;j<m;j*=2) ans+=m-j; } } cout<<ans<<endl; return 0; }