fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. int main(){
  6. ios::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8.  
  9. int T; cin >> T;
  10. while(T--){
  11. int n,q; cin>>n>>q;
  12. vector<ll>a(n);
  13. for(int i=0;i<n;i++) cin>>a[i];
  14.  
  15. ll xa = 0;
  16. for(ll x: a) xa ^= x;
  17.  
  18. while(q--){
  19. ll c; cin >> c;
  20. ll need = xa ^ c;
  21. if(need == 0){
  22. cout << 0 << "\n";
  23. continue;
  24. }
  25. ll best = LLONG_MAX;
  26. for(ll x: a){
  27. ll t = x ^ need;
  28. if(t >= x) best = min(best, t - x);
  29. }
  30. if(best == LLONG_MAX) cout << -1 << "\n";
  31. else cout << best << "\n";
  32. }
  33. }
  34. }
  35.  
Success #stdin #stdout 0.01s 5276KB
stdin
4
2 1
5 7
9
3 1
9 9 8
24
6 4
1 1 4 5 1 4
10
20
30
40
1 1
0
0
stdout
5
16
6
16
26
36
0