jzoj 4178游戏

Description

 

Input

Output

 

Data Constraint

 

Sol

  发现是阶梯Nim博弈。

  

#include<bits/stdc++.h>
#define N 1000009
using namespace std;
int el[N],c[N],p[N],ed,pa,n,m,siz[N],a[N],alc,anp,ans,x;
int get(int x){
    return ((el[x+1]&1)&&(el[x]-el[x+1]==1))?siz[x+1]:0;
}
signed main () {
//    freopen("a.in","r",stdin);
    scanf("%d%d",&m,&n);
    for (int i=1;i<=n;i++) scanf("%d",a+i);
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++)  {
        if (c[ed]!=a[i]) {
            p[++ed]=a[i]; c[ed]=a[i]+1;
        } else c[ed]++; 
    }
    if (c[ed]==m) return printf("%d\n",c[ed]-p[ed]),0;
    pa=m-2;
    for (int i=ed;i;i--) { 
        alc+=max(pa-c[i],0),pa=p[i];
        el[i]=alc; siz[i]=c[i]-p[i];
        anp^=(el[i]&1)*siz[i];
    }
    for (int i=ed;i;i--) {
        if (!el[i]) continue;
        if (el[i]&1)  ans+=(anp^siz[i])<siz[i]; 
        else { x=get(i);
//        assert(x==0);
            ans+=(siz[i]+x>=(x^anp)&&x<(x^anp)); 
//            cerr<<siz[i]<<' '<<x<<endl;
            }
//         ans+=((anp^x)<=x+siz[i])&&((anp^x)>x);
//         cerr<<siz[i]<<' '<<el[i]<<endl;
    }
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2018-10-30 19:39  泪寒之雪  阅读(152)  评论(0编辑  收藏  举报