思路:最终每个数的状态决定了操作次数的奇偶性,进而决定答案
考虑题目给出的$k$个限制会对每个数的终态产生什么影响:若给出的限制为$limit_x = 0$,则原来大于$x$的那些数在减少的过程中会被卡在$x + 1$,若给出的限制为$limit_x = y(y > 0)$,手玩不难发现这些限制只会影响每个数的终态,在游戏的过程中总有策略绕开这些限制使游戏继续,举个简单的例子:假如限制是$limit_3 = 1$,那么如果出现了$3$,虽然不能继续产生$3$,但是可以把$3$变成$2$,这样的话这个限制就相当于没有了
代码实现:可以用一个$vector$存取所有限制中$y = 0$的$x$,对于每个数最终被卡在哪里二分即可实现,其他限制用$map$模拟
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void solve()
{
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i ++ ) cin >> a[i];
map<int, int> mp;
vector<int> v;
for (int i = 0; i < k; i ++ )
{
int x, y;
cin >> x >> y;
mp[x] = y;
if (y == 0) v.push_back(x);
}
sort(v.begin(), v.end());
map<int, int> cnt;
for (int i = 0; i < n; i ++ )
{
if (v.empty()) cnt[0] ++ ;
else
{
int l = 0, r = v.size() - 1;
while (l < r)
{
int mid = l + r + 1 >> 1;
if (v[mid] < a[i]) l = mid;
else r = mid - 1;
}
if (v[r] < a[i]) cnt[v[r] + 1] ++ ;
else cnt[0] ++ ;
}
}
for (auto [x, y] : cnt)
if (mp.count(x) && y > mp[x])
{
cnt[x + 1] += y - mp[x];
cnt[x] = mp[x];
}
LL s = accumulate(a.begin(), a.end(), 0ll);
for (auto [x, y] : cnt)
s -= 1ll * x * y;
if (s & 1) cout << "Pico\n";
else cout << "FuuFuu\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T -- ) solve();
return 0;
}