[模板] 线性基
const int M = 61;
ll a[M + 1], tmp[M + 1];
bool flag; //判断0
void ins(ll x) {
for (int i = M; i >= 0; i--)
if (x & (1ll << i))
if (!a[i]) { a[i] = x; return; }
else x ^= a[i];
flag = true;
}
bool check(ll x) { //能否表示出x
for (int i = M; i >= 0; i--)
if (x & (1ll << i))
if (!a[i]) return false;
else x ^= a[i];
return true;
}
ll qmax() {
ll res = 0;
for (int i = M; i >= 0; i--)
res = max(res, res ^ a[i]);
return res;
}
ll qmin() {
if (flag) return 0;
for (int i = 0; i <= M; i++)
if (a[i]) return a[i];
}
ll query(ll k) { //第k小
ll res = 0;
int cnt = 0;
k -= flag;
if (!k) return 0;
for (int i = 0; i <= M; i++) {
for (int j = i - 1; j >= 0; j--)
if (a[i] & (1ll << j)) a[i] ^= a[j];
if (a[i]) tmp[cnt++] = a[i];
}
if (k >= (1ll << cnt)) return -1;
for (int i = 0; i < cnt; i++)
if (k & (1ll << i)) res ^= tmp[i];
return res;
}