• 【LOJ #6436】「PKUSC2018」神仙的游戏(NTT)


    传送门

    考虑对于一个长度为kkborderborder
    那么任意i,ji,j满足ij(mod  nk)iequiv j(mod n-k)要满足si=sjs_i=s_j
    考虑不满足的话一定是有i,ji,j满足sisjs_i ot=s_j
    变下形是(nk)i+(j)(n-k)|i+(-j)
    考虑类似卷积做字符串匹配的方法
    i[s[i]==0]xisum_{i}[s[i]==0]x^ij[s[j]==1]xnjsum_{j}[s[j]==1]x^{n-j}做卷积
    然后调和级数看所有p(xk)p*(x-k)的位置是否有值即可

    #include<bits/stdc++.h>
    using namespace std;
    #define cs const
    #define re register
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define ll long long
    #define pb push_back
    cs int RLEN=1<<20|1;
    inline char gc(){
    	static char ibuf[RLEN],*ib,*ob;
    	(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    	return (ib==ob)?EOF:*ib++;
    }
    inline int read(){
    	char ch=gc();
    	int res=0;bool f=1;
    	while(!isdigit(ch))f^=ch=='-',ch=gc();
    	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    	return f?res:-res;
    }
    inline int readstring(char *s){
    	int top=0;
    	char ch=gc();
    	while(isspace(ch))ch=gc();
    	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
    	return top;
    }
    template<class tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
    template<class tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
    cs int mod=998244353,G=3;
    inline int add(int a,int b){return (a+b)>=mod?(a+b-mod):(a+b);}
    inline void Add(int &a,int b){a=(a+b)>=mod?(a+b-mod):(a+b);}
    inline int dec(int a,int b){a-=b;return a+(a>>31&mod);}
    inline void Dec(int &a,int b){a-=b,a+=a>>31&mod;}
    inline int mul(int a,int b){static ll r;r=1ll*a*b;return r>=mod?r%mod:r;}
    inline void Mul(int &a,int b){static ll r;r=1ll*a*b;a=r>=mod?r%mod:r;}
    inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
    inline int Inv(int x){return ksm(x,mod-2);}
    cs int C=21;
    #define poly vector<int>
    poly w[C+1];
    int rev[(1<<C)|5];
    inline void init_rev(int lim){
    	for(int i=0;i<lim;i++)rev[i]=(rev[i>>1]>>1)|((i&1)*(lim>>1));
    }
    inline void init_w(){
    	for(int i=1;i<=C;i++)w[i].resize(1<<(i-1));
    	int wn=ksm(G,(mod-1)/(1<<C));
    	w[C][0]=1;
    	for(int i=1,lim=(1<<(C-1));i<lim;i++)
    	w[C][i]=mul(w[C][i-1],wn);
    	for(int i=C-1;i;i--)
    	for(int j=0,lim=1<<(i-1);j<lim;j++)
    	w[i][j]=w[i+1][j<<1];
    }
    inline void ntt(int *f,int lim,int kd){
    	for(int i=0;i<lim;i++)if(i>rev[i])swap(f[i],f[rev[i]]);
    	for(int mid=1,l=1,a0,a1;mid<lim;mid<<=1,l++)
    	for(int i=0;i<lim;i+=(mid<<1))
    	for(int j=0;j<mid;j++)
    	a0=f[i+j],a1=mul(f[i+j+mid],w[l][j]),f[i+j]=add(a0,a1),f[i+j+mid]=dec(a0,a1);
    	if(kd==-1){
    		reverse(f+1,f+lim);
    		for(int i=0,iv=Inv(lim);i<lim;i++)Mul(f[i],iv);
    	}
    }
    inline void pmul(int *a,int *b,int deg){
    	int lim=1;
    	while(lim<deg)lim<<=1;
    	init_rev(lim);
    	ntt(a,lim,1),ntt(b,lim,1);
    	for(int i=0;i<lim;i++)Mul(a[i],b[i]);
    	ntt(a,lim,-1);
    }
    cs int N=500005;
    char s[N];
    int n,A[(1<<C)+5],B[(1<<C)+5],c[(1<<C)+5];
    int main(){
    #ifdef Stargazer
    freopen("lx.in","r",stdin);
    #endif
    	init_w();
    	n=readstring(s);
    	for(int i=1;i<=n;i++)if(s[i]=='0')A[i]=1;else if(s[i]=='1')B[n-i]=1;
    	pmul(A,B,(n+1)*2);
    	for(int i=1;i<=(n+1)*2;i++)c[abs(i-n)]+=A[i];
    	ll ret=0;
    	for(int i=1;i<=n;i++){
    		int flag=1;
    		for(int j=0;j<=n;j+=i)flag&=(!c[j]);
    		ret^=1ll*(n-i)*(n-i)*flag;
    	}
    	cout<<(ret^(1ll*n*n))<<'
    ';
    	return 0;
    }
    
  • 相关阅读:
    实战(三):对游戏的破解“木叶忍者”
    实战(一):对“钉钉”的逆向(实现打卡功能)
    实战(二):对“微信”的逆向(实现界面自定义)
    iOS签名机制
    AM64汇编
    动态调试(二)
    动态调试(一)
    theos(二)
    murmurhash
    虚继承
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328349.html
Copyright © 2020-2023  润新知