CF1369F BareLee 题解

· · 题解

:::::success[Hint 1] 我们考虑 s_i 和 e_i 的奇偶性,并按照 s_i 的范围分类讨论并每次都尝试递归到子问题。 ::::: :::::success[Hint 2] 考虑如何将单次的胜负统计成全局的胜负。 :::::

对应 Hint 1:

我们设某个 (s,e) 是否必胜或必败为 w_{s,e} 或者 l_{s,e},我们优先考虑 w_{s,e}。

首先我们考虑按照 s,e 的奇偶性进行分类讨论,当 e 是奇数时:

那么我们接下来考虑 e 是偶数的情况。

对于 2s>e 的情况,操作一次乘二将直接失败,那么我们必定会不断加一,因此先手必胜当且仅当 s 是奇数。

对于 4s>e\ge 2s 的情况,我们发现乘二后一定会来到必败态,因此先手必胜。

对于其余情况,事实上等价于先超过 \lfloor\frac e4\rfloor 的失败,那么我们可以递归到 w_{s,\lfloor\frac e4\rfloor}。

下面我们考虑 l_{s,e},下文中失败和获胜的定义将交换。

我们依旧可以发现,当 2s>e 的情况,操作一次乘二直接获胜,因此先手必胜。

那么对于其余的情况,我们发现同样是先超过 \lfloor\frac e2\rfloor 的失败,因此我们可以递归到 w_{s,\lfloor\frac e2\rfloor},但是由于定义交换了实际上可能还需要取反。

对应 Hint 2:

我们考虑怎么将单次的答案统计为全局,这个是比较容易的,将 t 轮游戏倒序考虑,维护一个后缀的胜负情况 W 和 L(初始 W=0,L=1),然后对于每一局游戏,求出单局的 w,l,然后进行转移:

W\leftarrow (l\land W)\lor(w\land\overline{W}) L\leftarrow (l\land L)\lor(w\land\overline{L})

这样我们就做完了这道题。
时间复杂度为 \Theta(t\log V),空间复杂度为 \Theta(t)。 :::::success[code]

#include<bits/stdc++.h>
#define inl inline
#define int long long
#define lll __int128
#define fst ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,x,y) for(int i=x;i<=(y);++i) 
#define per(i,x,y) for(int i=x;i>=(y);--i)
#define rpr(i,x,y,z) for(int i=x;i<=(y);i+=z)
#define epe(i,x,y,z) for(int i=x;i>=(y);i-=z)
#define repe(i,x,y) for(i=x;i<=(y);++i) 
#define endl '\n'
#define INF 1e18
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front 
#define fi first
#define se second
#define lcm(x,y) x/__gcd(x,y)*y
#define ull unsigned long long
#define prr make_pair
#define pii pair<int,int> 
#define gt(s) getline(cin,s)
#define at(x,y) for(const auto &x:y)
#define ff fflush(stdout)
#define mt(x,y) memset(x,y,sizeof(x))
#define idg isdigit
#define fp(s) string ssss=s;freopen((ssss+".in").c_str(),"r",stdin);freopen((ssss+\
".out").c_str(),"w",stdout);
#define sstr stringstream 
#define all(x) x.begin(),x.end()
#define mcy(a,b) memcpy(a,b,sizeof(b))
#define ui unsigned
#define si signed
#define eb emplace_back
#define pff(x) ((x)*(x))
#define eush emplace
#define double long double
#define pdi pair<double,int>
#ifdef __unix__
#define gc getchar_unlocked
#else
#define gc _getchar_nolock
#endif
#ifdef __unix__
#define pc putchar_unlocked
#else
#define pc _putchar_nolock
#endif
using namespace std;
const int N=1e5+5;
int a[N],b[N];
inl bool checkw(int x,int y){
    if(y&1) return !(x&1);
    if(x<<1>y) return x&1;
    if(x<<2>y) return 1;
    return checkw(x,y>>2);
}
inl bool checkl(int x,int y){
    if(x<<1>y) return 1;
    return checkw(x,y>>1); 
} 
si main(){
    fst;
    int n;
    bool answ=0,ansl=1;
    cin>>n;
    rep(i,1,n) cin>>a[i]>>b[i];
    per(i,n,1){
        bool visw=checkw(a[i],b[i]),visl=checkl(a[i],b[i]);
        answ=visl&&answ||visw&&!answ;
        ansl=visl&&ansl||visw&&!ansl;
    }
    cout<<answ<<' '<<ansl<<endl; 
    return 0;
} 

:::::