Advertisement
Guest User

Untitled

a guest
Dec 29th, 2019
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <algorithm>
  7. #include <string>
  8. #include <cmath>
  9. #include <cstdio>
  10. #include <iomanip>
  11. #include <fstream>
  12. #include <cassert>
  13. #include <cstring>
  14. #include <unordered_set>
  15. #include <unordered_map>
  16. #include <numeric>
  17. #include <ctime>
  18. #include <bitset>
  19. #include <complex>
  20. #include <random>
  21.  
  22. using namespace std;
  23.  
  24. #define int long long
  25.  
  26. void solve() {
  27.     int n;
  28.     cin >> n;
  29.     vector<int> a(n);
  30.     for (auto &t : a) {
  31.         cin >> t;
  32.     }
  33.     int cs = 0;
  34.     int cx = 0;
  35.     for (auto t : a) {
  36.         cs += t;
  37.         cx ^= t;
  38.     }
  39.     //cs + x = 2 * (cx ^ x)
  40.     vector<int> ans;
  41.     if (cx > 0) ans.push_back(cx);
  42.     cs += cx;
  43.     ans.push_back(cs);
  44.     cout << ans.size() << endl;
  45.     for (auto t : ans) {
  46.         cout << t << ' ';
  47.     }
  48.     cout << endl;
  49. }
  50.  
  51. signed main() {
  52.     ios_base::sync_with_stdio(false);
  53.     cin.tie(0);
  54.    
  55.     int q;
  56.     cin >> q;
  57.     while (q--) {
  58.         solve();
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement