題目描述
給你
解題思路
首先你會發現,如果二進制中第
如果二進制中第
這樣的話就可以得到
例如:
…
參考代碼
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define maxn 100005
#define maxsq 62
#define ll long long
using namespace std;
bitset<maxn> f[maxsq+5],g[maxsq+5];
int n,tot;
int ans[maxn];
ll sum;
int p[maxsq+5];
int main(){
scanf("%d",&n);
fo(i,1,n) {
ll x;
scanf("%I64d",&x);
sum ^= x;
fo(j,0,maxsq)
if (x & (1ll << j)) g[j][i]=1;
}
fo(bit,0,1) {
fd(i,maxsq,0)
if (((sum >> i) & 1)==bit) {
f[++tot]=g[i];
if (bit==0) f[tot][n+1]=1;
else f[tot][n+1]=0;
fo(j,1,tot-1)
if (f[tot][p[j]]) f[tot] ^= f[j];
p[tot]=n+2;
fo(j,1,n)
if (f[tot][j]) {
p[tot]=j;
break;
}
if (p[tot]>n) {
tot--;
continue;
}
fo(j,1,tot-1)
if (f[j][p[tot]]) f[j] ^= f[tot];
}
}
fo(i,1,tot) ans[p[i]]=f[i][n+1];
fo(i,1,n) printf("%d ",2-ans[i]);
return 0;
}