學習博客學習
struct LinearBasis { # define N 64 # define reg register # define TT template<class T> # define LL long long LL base[N]; TT inline void Insert(T x) { for(reg LL i = N-1; ~i ; --i) if(x & (1LL << i))//可簡化成 (x >> i) { x ^= base[i]; if(base[i] == 0){base[i] ^= x;return;} } } TT inline bool Check(T x) { for(reg int i = N-1; ~i ; --i) if(base[i]) x ^= base[i]; return x == 0; } inline void Merge(LinearBasis x) { for(reg int i = N-1; ~i ; --i) if(x.base[i]) Insert(x.base[i]); } inline LL Xor_Sum_Max() { LL res = 0; for(reg int i = N-1; ~i ; --i) if((res ^ base[i]) > res) res ^= base[i]; return res; } inline LL Xor_Sum_Min() { LL res = 0; for(reg int i = N-1; ~i ; --i) if((res ^ base[i]) < res) res ^= base[i]; return res; } # undef N # undef reg # undef TT # undef LL } T;
洛谷 P4839spa
洛谷 P3812code
洛谷 P4570ci
洛谷 P3857get
洛谷 P4151博客
洛谷 P4301class