跳到正文

题解

CF1369F BareLee

ANDER_约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年9月3日
收录
2026年9月4日
更新
2026年11月18日
篇幅
约 3 分钟
题目
CF1369F

版本

  1. v1当前

听 zrl 在午饭时说的,在回宿舍前会了。

先考虑单组,设 ws,ew_{s,e} 与 ls,el_{s,e} 分别表示当前先手是否有必胜、必败状态。先从奇偶性入手发掘 ws,ew_{s,e} 性质,分类讨论:

  • ee 为奇数时:
    • ss 为偶数时,注意到只需不断加一就能必胜,因为对方拿奇数,操作只能使其变回偶数。
    • ss 为奇数时,操作一次就变成偶数的情形了,没有必胜策略。
  • ee 为偶数时:
    • 2s>e2s > e 时,先手乘二就爆了,只能加一。胜负由操作次数奇偶性决定。
    • 4s>e4s > e 时,乘二跳到上一部分,且必为偶数,故有必胜策略。
    • 4s≤e4s \le e 时,先过 ⌊e4⌋\lfloor\frac{e}{4}\rfloor 的必胜,故化为 ws,⌊e4⌋w_{s,\lfloor\frac{e}{4}\rfloor}。

ls,el_{s,e} 较为简单:

  • 2s>e2s > e 时,有必败策略。
  • 2s≤e2s \le e 时,先过 ⌊e2⌋\lfloor\frac{e}{2}\rfloor 的有必败策略,化为 ws,⌊e2⌋w_{s,\lfloor\frac{e}{2}\rfloor}。

这个时候单组就能 Θ(log⁡V)\Theta(\log V) 做了。

现在考虑把多组合起来,可以倒着合并。令 W,LW,L 为最终答案,初始 W=0,L=1W = 0,L = 1。设当前组对应 w,lw,l。得到:

W=(l∧W)∨(w∧¬W)L=(l∧L)∨(w∧¬L)W = (l \land W) \lor (w \land \neg W)\\ L = (l\land L) \lor (w \land \neg L)

就能 Θ(tlog⁡V)\Theta(t\log V) 做了。

C++
#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;
}
原文