P3235 [HNOI2014]江南樂
阿新 • • 發佈:2018-12-04
yyb巨巨的題解
沒看懂為什麼整除分塊的時候只要做兩個就夠了……
//minamoto #include<bits/stdc++.h> #define R register int #define fp(i,a,b) for(R i=a,I=b+1;i<I;++i) #define fd(i,a,b) for(R i=a,I=b-1;i>I;--i) using namespace std; char buf[1<<21],*p1=buf,*p2=buf; inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;} int read(){ R res,f=1;char ch; while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1); for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0'); return res*f; } const int N=1e5+5; int SG[N],vis[N]; int Sg(int x){ if(SG[x]!=-1)return SG[x]; for(R i=2,k;i<=x;i=k+1){ k=x/(x/i); for(R j=i;j<=min(i+1,k);++j){ R s=0; if((x%j)&1)s^=Sg(x/j+1); if((j-x%j)&1)s^=Sg(x/j); vis[s]=x; } } fp(i,0,N)if(vis[i]!=x)return SG[x]=i; } int main(){ // freopen("testdata.in","r",stdin); int T=read(),F=read();memset(SG,-1,sizeof(SG)); fp(i,0,F-1)SG[i]=0; while(T--){ int n=read(),s=0; while(n--)s^=Sg(read()); printf("%d ",(bool)s); }return 0; }