【LOJ】#2126. 「HAOI2015」數組遊戲
阿新 • • 發佈:2018-09-17
() open class line include fde str lse pos
題解
簡單分析一下就知道\(\lfloor \frac{N}{i} \rfloor\)相同的\(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(‘\n‘) #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; }
【LOJ】#2126. 「HAOI2015」數組遊戲