听 zrl 在午饭时说的,在回宿舍前会了。
先考虑单组,设 与 分别表示当前先手是否有必胜、必败状态。先从奇偶性入手发掘 性质,分类讨论:
- 为奇数时:
- 为偶数时,注意到只需不断加一就能必胜,因为对方拿奇数,操作只能使其变回偶数。
- 为奇数时,操作一次就变成偶数的情形了,没有必胜策略。
- 为偶数时:
- 时,先手乘二就爆了,只能加一。胜负由操作次数奇偶性决定。
- 时,乘二跳到上一部分,且必为偶数,故有必胜策略。
- 时,先过 的必胜,故化为 。
较为简单:
- 时,有必败策略。
- 时,先过 的有必败策略,化为 。
这个时候单组就能 做了。
现在考虑把多组合起来,可以倒着合并。令 为最终答案,初始 。设当前组对应 。得到:
就能 做了。
#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;
}