为下个陌生人绽放同样微笑
我们考虑把原问题转化为 Nim 游戏:原问题等价于有四堆石子:
考虑 A 能影响的,即
我们考虑枚举
所以直接差分即可,时间复杂度
namespace Loop1st {
int x1, x2, c[N];
void Main(int tc) {
cin >> x1 >> x2;
for (int i = 0; i < x2; i++) c[i] = 0;
for (int a = 0; a < x2; a++) {
int b = x2 - a, now = 0;
for (int i = 20; i >= 0; i--) if (b >> i & 1) {
int L = ((a ^ now) >> i) << i, R = L + (1 << i);
c[L]++; c[R]--;
now |= 1 << i;
}
}
for (int i = 1; i < x2; i++) c[i] += c[i - 1];
int mx = 1 << 30, ans = 0;
for (int i = 0; i < x1; i++) {
int val = (i < x2 ? c[i] : 0);
if (val < mx) mx = val, ans = i;
}
cout << "1 " << x1 - ans << '\n';
}
}