Here are the questions.
Considering the first and second numbers x, y, we can find that S is determined only on the highest bit of (x XOR y) (if x = = y is not restricted), and we can deduce what is 1/0.
So let’s simulate this operation and decide if there’s any contradiction in the restriction. If there’s no contradiction, the answer is 2 ^ free bit.
#include<bits/stdc++.h> #define ll long long using namespace std; int n,ban[67]; ll now,pre,Xor,c[67],ans=1; int main(){ scanf("%d",&n),fill(ban,ban+60,-1); c[0]=1; for(int i=1;i<=60;i++) c[i]=c[i-1]+c[i-1]; for(int i=1;i<=n;pre=now,i++){ scanf("%lld",&now); if(!pre) continue; for(int j=59;j>=0;j--) if((now&c[j])^(pre&c[j])){ if(now&c[j]){ if(ban[j]==1){ puts("0"); return 0;} ban[j]=0; } else{ if(ban[j]==0){ puts("0"); return 0;} ban[j]=1; } break; } } for(int i=0;i<60;i++) if(ban[i]==-1) ans*=2ll; cout<<ans<<endl; return 0; }