在 这个帖子 中,说不会查询不在范围内的数字,但是为什么下面的代码会在 #6、#8、#10 中 Runtime Error?
请大佬指教。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 10086;
int n, x, q, a[35], d[35], cnt;
inline void insert(int x){
for(int i = 31; ~i; i--){
if(x >> i & 1){
if(!a[i]){
a[i] = x;
return ;
}
else x ^= a[i];
}
}
}
inline void prepa(){
for(int i = 0; i <= 31; i++){
for(int j = i - 1; ~j; j--){
if(a[i] >> j & 1) a[i] ^= a[j];
}
if(a[i]) d[cnt++] = a[i];
}
}
inline int ksm(int x, int y){
int res = 1;
while(y){
if(y & 1) res = res * x % mod;
y >>= 1, x = x * x % mod;
}
return res;
}
inline int query(int x){
int res = 0;
for(int i = cnt - 1; ~i; i--){
if(x & d[i]){
x ^= d[i];
(res += (1 << i) % mod) % mod;
}
}
if(x) assert(0);
return (res + 1) % mod;//set can be empty
}
signed main(){
scanf("%lld", &n);
for(int i = 1; i <= n; i++){
scanf("%lld", &x);
insert(x);
}
prepa();
sort(d, d + cnt);
scanf("%lld", &q);
printf("%lld\n", (1ll * (query(q) - 1) * ksm(2, n - cnt) + 1) % mod);
return 0;
}