[Explanations] LOJ6060 Set (linear-yl)

[Explanations] LOJ6060 Set (linear-yl)

barley gql

Set and the number of all of the exclusive-OR \ (S \) , the answer is in the (\ max (x_1 + S \ and x_1) \) \ under the premise \ (\ min x_1 \) output \ (x_1 \)

Converting what is the \ (\ max (x_2 + S \ and x_2), st \ max x_2 \)

Consider first the outer layer obtained greedily \ (\ max \)

Greedy bit, set \ (u_i \) of \ (S \) of \ (\ I) at position \ ( 'bit \) , \ (u_i \) a \ (0/1 \) variable

  • \ (u_i = 1 \) when, for \ (x_2 \) this one we do not have any request, because no matter \ (x_2 \) value on the position, the outer layer \ (\ max \) unchanged.
  • \ (u_i = 0 \) when, for \ (x_2 \) This requires us to have a \ (bit \) there \ (bit \) , so you can have the answer to \ (2 \ times 2 ^ i \) contribution.

Due to meet the requirements of \ (x_2 \) there are many, we now want to find the largest of the kind, based on the direct linear set into the like. Specific implementation code annotated, the text illustrates the difficult!

Gql equivalent to repeat the code

//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>

using namespace std;  typedef long long ll;
inline ll qr(){
      register ll ret=0,f=0;
      register char c=getchar();
      while(c<48||c>57)f|=c==45,c=getchar();
      while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
      return f?-ret:ret;
}
const int maxn=1e5+5;
ll data[maxn];
ll base[66];
ll num[66];   
ll n,S;

inline void insert(ll x){
      for(register int t=63;t;--t)
        if(!(S&num[t])&&(x&num[t])){
          if(!base[t]) return void(base[t]=x);
              x^=base[t];
        }
      //假如当前元素可以按照条件一的条件插入,就return了,运行下面的代码是条件二
      for(register int t=63;t;--t)
        if((S&num[t])&&(x&num[t])){
          if(!base[t]) return void(base[t]=x);
          x^=base[t];
        }       
}

inline ll top(){
      ll ret=0;
      //构造满足条件一二
      for(register int t=63;t;--t)
        if(!(S&num[t])&&!(ret&num[t])) ret^=base[t];
      
      //构造x最大
      for(register int t=63;t;--t)
        if( (S&num[t])&&!(ret&num[t])) ret^=base[t];
      return ret;
}

int main(){
      num[1]=1;
      for(register int t=2;t<=63;++t) num[t]=num[t-1]<<1;
      n=qr();
      for(register int t=1;t<=n;++t) data[t]=qr(),S^=data[t];
      for(register int t=1;t<=n;++t) insert(data[t]);
      cout<<(top()^S)<<endl;
      return 0;
}

Guess you like

Origin www.cnblogs.com/winlere/p/11298849.html