fork download
  1. #include <cstdio>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. const int MAXN = 1048576;
  6. long long solve(vector<int> &contain)
  7. {
  8. long long ans = 0;
  9. for (int j = 0; (1<<j) < MAXN; j++) {
  10. for (int i = 0; i < MAXN; i++) if (!(i & (1<<j))) {
  11. contain[i] += contain[i^(1<<j)];
  12. }
  13. }
  14. for (int i = 0; i < MAXN; i++) {
  15. if (__builtin_popcount(i) & 1) ans -= (contain[i]*1ll*(contain[i]-1));
  16. else ans += (contain[i]*1ll*(contain[i]-1));
  17. }
  18. return ans;
  19. }
  20. void tmain()
  21. {
  22. int N;
  23. vector<int> contain(MAXN);
  24. scanf("%d",&N);
  25. for(int i=0;i<N;i++)
  26. {
  27. int t;
  28. scanf("%d",&t);
  29. contain[t]++;
  30. }
  31.  
  32. printf("%lld\n",contain[0]+solve(contain));
  33. }
  34. int main()
  35. {
  36. int T;
  37. scanf("%d",&T);
  38. while(T--)
  39. tmain();
  40. return 0;
  41. }
Success #stdin #stdout 0.05s 7292KB
stdin
2
5
41 47 34 40 29
3
1 2 3
stdout
2
2