不知道为啥 WA*20。
思路就是求每堆的 sg,求的方法就直接在前面找一个最小的没有出现过的数。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
int n,m,a[N],ans;
map<int,int> mp,sg,vis;
map<int,vector<int> > Mp;
signed main(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]),mp[a[i]]^=1;
for(int i=1,l,r;i<=m;i++){
scanf("%lld%lld",&l,&r);
if(!mp.count(l))mp[l]=0;
if(!mp.count(l-r))mp[l-r]=0;
Mp[l].push_back(l-r);
}
int now=0,las=0;
for(auto i:mp){
int x=i.first;
now+=x-las,las=x;
sg[x]=now;
for(int y:Mp[x]){vis[y]--;if(!vis[y])sg[x]=min(sg[x],y);}
for(int y:Mp[x])vis[y]++;
vis[sg[x]]++;
if(mp[x])ans^=sg[x];
}
puts(ans?"Takahashi":"Aoki");
}