CodeForces 925 C Big Secret
题解:
若 cur ^ x > cur 则 x2进制下最高位的1 所对应cur的那个位置是0, 否则数字一定变小。
我们可以将每个数的最高位找出来。
然后我们从低位去check某位是不是0。
虽然对于每个数来说都只要考虑最高位就好了, 但是相对的最高位会影响比他低位置的数, 低位不会影响高位, 所以先填低位。
代码:
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL _INF = 0xc0c0c0c0c0c0c0c0; const LL mod = (int)1e9+7; const int N = 1e5 + 100; vector<LL> vc[60]; LL ans[N], b[N]; int main(){ int n; scanf("%d", &n); for(int i = 1; i <= n; ++i){ scanf("%lld", &b[i]); for(int j = 59; j >= 0; --j) if((b[i]>>j)&1) { vc[j].pb(b[i]); break; } } LL cur = 0; for(int i = 1; i <= n; ++i){ int f = 0; for(int j = 0; j < 60; ++j){ if(vc[j].size() && !((cur>>j) & 1)){ ans[i] = vc[j].back(); vc[j].pop_back(); cur ^= ans[i]; f = 1; break; } } if(!f){ puts("No"); return 0; } } puts("Yes"); for(int i = 1; i <= n; ++i){ printf("%lld%c", ans[i], " \n"[i==n]); } return 0; }