Nim博弈,异或性质——2020-camp-day2-C

#include<bits/stdc++.h>
using namespace std;
const int M =1e5+7;
typedef long long ll;
ll a[M],ct[M];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    ll sm=0;
    for(int i=1;i<=n;i++)
    {
    //    cout<<"--"<<endl;
        sm^=a[i];
        for(int j=0;j<=60;j++)
        if((a[i]>>j)&1)ct[j]++;
        //cout<<sm<<"  "<<i<<endl;
        if(sm==0)
        {
            puts("0");
            continue;
        }
        for(int j=60;j>=0;j--)
        if((sm>>j)&1)
        {
            printf("%lld
",ct[j]);
            break;
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zsben991126/p/12197477.html