Topic link
Meaning
There are n numbers and q Q, and each query gives a positive integer k K, asking what number of K K is small in all numbers of n n numbers or combinations, and if not, output −1-1.
Ideas:
First, the N-n number of the different or linear base is constructed.
Assuming that non 0 linear bases have a total of tot tot, the results of the first 1− (x−1) n (x-1) linear group, regardless of linear combination, are less than the X-X linear basis for the X-X linear basis.
Because the X-X linear base assumes that the highest bit of 1 1 is in K K, because a carry is different or not, it is not possible to combine a small base with a bits greater than or equal to K K of 1 1.
In this case, the linear combination of the linear basis of the size of the order is very similar to the binary size of the order, such as:
10000 100,001 is larger than the 01111,01101,01110 01111,01101,01110, such as the 0xxxx 0xxxx binary number.
Therefore, the K-K binary decomposition can be considered, and if the first I is 1, then the contribution of the linear base from small to large sorted.
Therefore, for TOT tot linear basis, the case of linear combination has 2tot−1 2^{tot}-1 species altogether.
But this does not include 0 0.
So you can give a special sentence, if n n vectors are all used to form a linear basis, there will be no differences or 0 0.
So the problem is solved.
Code:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std;
typedef long Long LL;
const int A = 1e4 + 10;
ll A[a],b[110],c[a];
int N,zero,tot;
void Init () {zero = tot = 0;
Memset (b,0,sizeof (b)); for (int i=1; i<=n i++) for (int j=62; j>=0; j--) {if (a[i]>>j) &1) {if (b[j)) A[i] ^= b[
J];
else{B[j] = a[i];tot++;
for (int k=j-1; k>=0 k--) if (B[k] && ((b[j]>>k) &1)) B[j] ^= b[k];
for (int k=j+1; k<=62;k++) if ((b[k]>>j) &1) b[k] ^= b[j];
Break
}} zero = (tot<n); tot = 0;
for (int i=0; i<=62 i++) if (b[i)) c[tot++] = B[i];
ll solve (ll K) {if (zero) k--;
if (k >= (1ll<<tot)) return-1;
ll ans = 0;
for (int i=0; i<=62 i++) if ((k>>i) &1) ans ^= c[i];
return ans;
int main () {int t,_=1;scanf ("%d", &t); WhilE (t--) {scanf ("%d", &n);
for (int i=1; i<=n i++) scanf ("%i64d", &a[i));
Init ();
int q;scanf ("%d", &q);
printf ("Case #%d:\n", _++);
while (q--) {ll k;scanf ("%i64d", &k); printf