Description
有一个长度为N的数组,甲乙两人在上面进行这样一个游戏:首先,数组上有一些格子是白的,有一些是黑的。然后两人轮流进行操作。每次操作选择一个白色的格子,假设它的下标为x。接着,选择一个大小在1~n/x之间的整数k,然后将下标为x、2x、…、kx的格子都进行颜色翻转。不能操作的人输。现在甲(先手)有一些询问。每次他会给你一个数组的初始状态,你要求出对于这种初始状态他是否有必胜策略。
Solution
许久没有做博弈题,又忘了这类题的一个性质……
就是说这种状态的SG值就是若干个子状态的SG值异或起来,也就是说每个白色格子是独立的,算出每个白色格子的SG值即可。
然后显然
⌊
n
i
⌋
\lfloor {n\over i} \rfloor
⌊in⌋相同的SG值也相同,因为
S
G
i
=
m
e
x
{
S
G
2
i
,
S
G
2
i
x
o
r
S
G
3
i
.
.
.
}
SG_i=\text mex\{SG_{2i},SG_{2i}\ xor\ SG_{3i}...\}
SGi=mex{SG2i,SG2i xor SG3i...},所以一共有
n
\sqrt n
n种不同的SG值,暴力求每一种的时候也要分块。
复杂度只知道小于
O
(
n
)
O(n)
O(n),具体不清楚。
Code
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=70000;
const int mod=3007003;
const int inf=2147483647;
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
int Hash[mod],V[mod];
void insert(int x,int v)
{
int t=x%mod;
while(Hash[t])t=((t==mod-1)?0:t+1);
Hash[t]=x;V[t]=v;
}
int query(int x)
{
int t=x%mod;
while(Hash[t]&&Hash[t]!=x)t=((t==mod-1)?0:t+1);
if(!Hash[t])return -1;
return V[t];
}
int n,p[Maxn],sg[Maxn],lp=0;
int mark[Maxn],tim=0;
int main()
{
n=read();
int pos,cnt=0;
for(int i=1;i<=n;i=pos+1)pos=n/(n/i),p[++lp]=i,insert(n/i,lp);
sg[lp]=1;
for(int i=lp-1;i;i--)
{
int x=p[i],m=n/x,t=0,last=1,c=1;++tim;
for(int j=2;j<=m;j=pos+1)
{
pos=m/(m/j);
mark[t]=mark[t^sg[query(m/j)]]=tim;
if((pos-last)&1)t^=sg[query(m/j)];
last=pos;
}
while(mark[c]==tim)c++;
sg[i]=c;
}
int T=read();
while(T--)
{
int w=read(),ans=0;
while(w--)ans^=sg[query(n/read())];
if(!ans)puts("No");
else puts("Yes");
}
}