题解
简单分析一下就知道(lfloor frac{N}{i} floor)相同的(i)的(sg)函数相同
所以我们只要算(sqrt{n})个(sg)函数就好
算每一个(sg(m))的时候我们可以通过把这个数再拆成(sqrt{m})段来计算(sg)值
复杂度用积分分析是(n^{frac{3}{4}})
代码
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('
')
#define space putchar(' ')
#define MAXN 100005
#define mo 994711
//#define ivorysi
using namespace std;
typedef long long int64;
typedef long double db;
typedef unsigned int u32;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {putchar('-');x = -x;}
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
struct node {
int x,val,next;
}E[1000005];
int head[mo + 5],sumE,N;
int L[1000005],cnt,tmp[100005],tot;
void add(int u,int x) {
E[++sumE].x = x;
E[sumE].next = head[u];
head[u] = sumE;
}
void Insert(int x,int v) {
for(int i = head[x % mo] ; i ; i = E[i].next) {
if(E[i].x == x) {E[i].val = v;return;}
}
}
int Query(int x) {
for(int i = head[x % mo] ; i ; i = E[i].next) {
if(E[i].x == x) {return E[i].val;}
}
}
void Init() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
int r = N / (N / i);
L[++cnt] = N / i;
add(L[cnt] % mo,L[cnt]);
i = r;
}
Insert(1,1);
for(int i = cnt - 1 ; i >= 1 ; --i) {
tot = 0;int pre = 0;
tmp[++tot] = 0;
for(int j = 2 ; j <= L[i] ; ++j) {
int r = L[i] / (L[i] / j);
int x = Query(L[i] / j);
tmp[++tot] = x ^ pre;
if((r - j + 1) & 1) pre ^= x;
j = r;
}
sort(tmp + 1,tmp + tot + 1);
tot = unique(tmp + 1,tmp + tot + 1) - tmp - 1;
int p = 0,pos = 1;
while(tmp[pos] == p) {++p;++pos;}
Insert(L[i],p);
}
}
void Solve() {
int K,W;
read(K);
while(K--) {
read(W);
int ans = 0,a;
for(int i = 1 ; i <= W ; ++i) {
read(a);
ans ^= Query(N / a);
}
if(!ans) puts("No");
else puts("Yes");
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Init();
Solve();
return 0;
}