记录编号 162028 评测结果 AAAAAAAAAA
题目名称 [HAOI 2015]数组游戏 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 1.172 s
提交时间 2015-05-13 12:22:07 内存使用 24.23 MiB
显示代码纯文本
  1. /*****************************************************************************/
  2. /******************************Designed By Asm.Def****************************/
  3. /*****************************************************************************/
  4. #include <cstring>
  5. #include <cstdio>
  6. #include <algorithm>
  7. #include <cstdlib>
  8. #include <cctype>
  9. #include <ctime>
  10. #define SetFile(x) (freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) )
  11. //#define FREAD
  12. #define FREADLENTH 5000000
  13. #ifdef FREAD
  14. char *fread_ptr = (char*)malloc(FREADLENTH);
  15. #define getc() (*(fread_ptr++))
  16. #else
  17. #define getc() getchar()
  18. #endif
  19. using namespace std;
  20. template<class T>inline void getd(T &x){
  21. int ch = getc();bool neg = false;
  22. while(!isdigit(ch) && ch != '-')ch = getc();
  23. if(ch == '-')neg = true, ch = getc();
  24. x = ch - '0';
  25. while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
  26. if(neg)x = -x;
  27. }
  28. /*******************************************************************************/
  29. const int maxn = 64000, P = 2000003;
  30. int N, val[maxn], vcnt, vt[maxn], checklist[maxn];
  31. bool check[maxn];
  32. int SG[maxn];
  33. #include <vector>
  34.  
  35. vector<int> Hash[P];
  36. typedef vector<int>::iterator iterator;
  37.  
  38. inline int find(const int *L, size_t len, int x){
  39. const int *R = L + len - 1, *mid;
  40. while(L <= R){
  41. mid = L + (R-L) / 2;
  42. if(val[*mid] > x)L = mid + 1;
  43. else R = mid - 1;
  44. }
  45. return *L;
  46. }
  47.  
  48. inline int ind(int x){
  49. vector<int> &v = Hash[x % P];
  50. return find(&v[0], v.size(), x);
  51. }
  52.  
  53. inline void init(){
  54. getd(N);
  55. int i, j, t, s, vtcnt, c, tmp;
  56. int ccnt;//回滚check数组
  57. for(i = 1;i * i <= N;++i)val[vcnt++] = i;
  58. for(j = N / i;j;--j)val[vcnt++] = N / j;
  59. for(i = 0;i < vcnt;++i){
  60. t = val[i];s = ccnt = vtcnt = 0;
  61. for(j = 1;j * j <= t;++j)vt[vtcnt++] = j;
  62. for(j = t / j;j;--j)vt[vtcnt++] = t / j;//vt:乘k之后能出现的长度
  63. for(j = vtcnt-2;j >= 0;--j){
  64. //printf("ind(%d) = %d\n", vt[j], ind(vt[j]));
  65. tmp = SG[ind(vt[j])];
  66. c = t / vt[j] - t / (vt[j] + 1);//出现次数
  67. check[checklist[ccnt++] = s ^ tmp] = true;
  68. if(c & 1)s ^= tmp;
  69. }
  70. j = 1;while(check[j])++j;
  71. SG[i] = j;
  72. Hash[t % P].push_back(i);
  73. for(j = 0;j < ccnt;++j)check[checklist[j]] = false;
  74. }
  75. }
  76.  
  77. inline void work(){
  78. int K, qcnt, sum, t;
  79. getd(K);while(K--){
  80. getd(qcnt);
  81. sum = 0;
  82. while(qcnt--){
  83. getd(t);
  84. sum ^= SG[ind(N / t)];
  85. }
  86. if(sum)puts("Yes");
  87. else puts("No");
  88. }
  89. }
  90.  
  91. int main(){
  92.  
  93. #ifdef DEBUG
  94. freopen("test.txt", "r", stdin);
  95. #else
  96. SetFile(haoi2015_t3);
  97. #endif
  98. #ifdef FREAD
  99. fread(fread_ptr, 1, FREADLENTH, stdin);
  100. #endif
  101. init();
  102. work();
  103.  
  104. #ifdef DEBUG
  105. printf("\n%.3lf sec\n", (double)clock() / CLOCKS_PER_SEC);
  106. #endif
  107. return 0;
  108. }
  109.