AT_abc278_G
题意
有 个物品排成一排,每次可以删除一个长度在 到 之间的连续区间,两个人轮流删除,问谁会赢并构造必胜方案。
思路
首先我们注意到 以此我们考虑直接计算 SG 函数,是 的,使用一些优化 (奇技淫巧) 也许可以通过。
然后我们考虑分类讨论:
- 当 时先手必胜,先手可以通过取走中间 个( 的奇偶性与 相同)构造两个一样长的区间,然后对称的模仿后手即可;
- 有可能不能构造,此时我们再用 SG 函数就可以了,因为此时我们发现每一个长度的 SG 函数值都相等,于是考虑根据定义暴力计算 SG 函数的值:
如果 则先手必胜,反之则后手必胜。
然后我们找出一段区间 ,裂成 和 。为保证能够必胜,则当前所有区间的 SG 函数值的 记作 要能够满足:
直接用 set 维护连续段即可喵。(为什么这么像某个叫 ODT 的数据结构呢) 。
Code:
// Where should I linger? I ask myself.
#include <bits/stdc++.h>
#define FILE
#define IOS() std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0)
#define re register
// #define int long long
using pii = std::pair <int, int>;
using ll = long long;
using std::endl;
constexpr int N = 2005;
int n, l, r, sg[N], cnt[N];
std::vector <int> s;
std::set <std::pair <int, int> > set;
int cur;
void solve(int p){
std::cout << "First" << endl;
std::cout << n / 2 - p / 2 + 1 << ' ' << p << endl;
int l = n / 2 - p / 2 + 1, r = l + p - 1;
int x, y;
while(std::cin >> x >> y, x > 0) if(x < l) std::cout << x + r << ' ' << y << endl; else std::cout << x - r << ' ' << y << endl;
}
bool check(int l, int r){
auto it = set.upper_bound({l, n});
if(it == set.begin()) return 0;
--it;
if(l < it->first || it->second < r) return 0;
return (cur ^ sg[it->second - it->first + 1] ^ sg[l - it->first] ^ sg[it->second - r]) == 0;
}
void split(int l, int r){
auto it = set.upper_bound({l, n});
--it;
int x = it->first, y = it->second;
set.erase(it);
if(r < y) set.emplace(r + 1, y);
if(x < l) set.emplace(x, l - 1);
}
void solve(){
cur = 0;
for(auto it = set.begin(); it != set.end(); ++it) cur ^= sg[it->second - it->first + 1];
for(int i = 1; i <= n - l + 1; ++i) if(check(i, i + l - 1)){
std::cout << i << ' ' << l << endl;
split(i, i + l - 1);
return ;
}
}
int main(){
#ifndef FILE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
IOS();
std::cin >> n >> l >> r;
if(l != r){
solve(l + (l % 2 != n % 2));
return 0;
}
if(l % 2 == n % 2){
solve(l);
return 0;
}
for(int i = l; i <= n; ++i){
for(int j = 0; j <= i - l; ++j) s.emplace_back(sg[j] ^ sg[i - j - l]);
for(auto j : s) cnt[j]++;
while(cnt[sg[i]]) ++sg[i];
for(auto j : s) cnt[j]--;
s.clear();
}
set.emplace(1, n);
if(sg[n]) std::cout << "First" << endl, solve();
else std::cout << "Second" << endl;
int x, y;
while(std::cin >> x >> y, x > 0) split(x, x + y - 1), solve();
return 0;
}
// 阿乌拉,投降吧
// ......
// 阿乌拉,站在你面前的是活了上千年的魔法使