CF1369F BareLee
ANDER_
·
·
题解
听 zrl 在午饭时说的,在回宿舍前会了。
先考虑单组,设 w_{s,e} 与 l_{s,e} 分别表示当前先手是否有必胜、必败状态。先从奇偶性入手发掘 w_{s,e} 性质,分类讨论:
-
- $s$ 为偶数时,注意到只需不断加一就能必胜,因为对方拿奇数,操作只能使其变回偶数。
- $s$ 为奇数时,操作一次就变成偶数的情形了,没有必胜策略。
-
- $2s > e$ 时,先手乘二就爆了,只能加一。胜负由操作次数奇偶性决定。
- $4s > e$ 时,乘二跳到上一部分,且必为偶数,故有必胜策略。
- $4s \le e$ 时,先过 $\lfloor\frac{e}{4}\rfloor$ 的必胜,故化为 $w_{s,\lfloor\frac{e}{4}\rfloor}$。
- $2s > e$ 时,有必败策略。
- $2s \le e$ 时,先过 $\lfloor\frac{e}{2}\rfloor$ 的有必败策略,化为 $w_{s,\lfloor\frac{e}{2}\rfloor}$。
这个时候单组就能 $\Theta(\log V)$ 做了。
现在考虑把多组合起来,可以倒着合并。令 $W,L$ 为最终答案,初始 $W = 0,L = 1$。设当前组对应 $w,l$。得到:
$$
W = (l \land W) \lor (w \land \neg W)\\
L = (l\land L) \lor (w \land \neg L)
$$
就能 $\Theta(t\log V)$ 做了。
``` cpp
#include <bits/stdc++.h>
#define endl '\n'
// #define MSOD
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
bool cw(ll s, ll e) {
if((e & 1)) return !(s & 1);
else if(s << 1 > e) return (s & 1);
else if(s << 2 > e) return 1;
else return cw(s, e >> 2);
}
bool cl(ll s, ll e) {
if(s << 1 > e) return 1;
else return cw(s, e >> 1);
}
int n;
ll ss[N], ee[N];
void TEST() {
cin>>n;
for(int i = 1 ; i <= n ; i ++) cin>>ss[i]>>ee[i];
bool W = false, L = true;
for(int i = n ; i >= 1 ; i --) {
bool wn = cw(ss[i], ee[i]), ls = cl(ss[i], ee[i]);
W = (ls && W) || (wn && !W), L = (ls && L) || (wn && !L);
}
cout<<W<<" "<<L<<endl;
return;
}
signed main() {
ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
int TC = 1;
#ifdef MSOD
cin>>TC;
#endif
while(TC --) TEST();
return 0;
}
```