1 条题解
-
0
真只有蓝题吗?
思路
首先应当刻画怎样的局面是先手必胜的。注意到若序列中每一种元素出现次数均为偶数,此时是先手必败的,因为后手总是可以模仿先手的任何策略;反之一定是先手必胜的,因为先手第一步可以选择最大的出现次数为奇数的一个元素进行删除,此时局面变成所有元素出现次数均为偶数的局面,显然此时先手是必胜的。
接下来考虑如何 check 一个方案,观察到值域较小,考虑枚举 ,此时的贡献是 后序列中每一种元素出现次数均为偶数或 的 的数量,复杂度 。
由于接下来的 ,所以 能写成 的形式,并且 是不降的,这启发我们对原问题进行一步转换,记 ,那么每一次操作变成可以选择一个 。
显然 ,所以贡献的条件变成了(下面的出现次数是对于 来说的):
- 出现次数为奇数的元素有一个,显然当这个元素为 时才能有贡献。
- 出现次数为奇数的元素有两个,分别记作 ,其中 ,显然只有 时有贡献,因为操作一次后的影响是 $cnt_a \leftarrow cnt_a + 1,cnt_b \leftarrow cnt_b - 1$。
- 出现次数为奇数的元素为零或大于二显然都无法做出贡献。
此时暴力做复杂度 。
Code
#include <bits/stdc++.h> #define re register #define int long long using namespace std; const int N = 1e5 + 10,M = 1e6 + 10; int n,ans; int arr[N],cnt[M],num[M]; inline int read(){ int r = 0,w = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9'){ r = (r << 3) + (r << 1) + (c ^ 48); c = getchar(); } return r * w; } signed main(){ n = read(); for (re int i = 1;i <= n;i++) cnt[arr[i] = read()]++; for (re int i = 1;i <= 1e6;i++) cnt[i] += cnt[i - 1]; for (re int i = 1;i <= 1e6;i++){ int tot = 0,lim = 1e6 / i; for (re int j = 1;j <= lim;j++) num[j] = cnt[min<int>(1e6,i * (j + 1) - 1)] - cnt[i * j - 1]; for (re int j = 1;j <= lim;j++) tot += (num[j] & 1); if (tot == 1){ if (num[1] & 1) ans += num[1]; } else if (tot == 2){ for (re int j = 2;j <= lim;j++){ if ((num[j - 1] & 1) && (num[j] & 1)) ans += num[j]; } } } printf("%lld",ans); return 0; }
- 1
信息
- ID
- 7051
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者