fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4.  
  5. void solve() {
  6. int n;
  7. cin >> n;
  8. vector<int> v(n);
  9. for(int i=0;i<n;i++){
  10. cin>>v[i];
  11. }
  12. vector<int> a(n,0);
  13. for(int i=0;i<n;i++){
  14. for(int j=0;j<=31;j++){
  15. if((v[i]&(1<<j))){
  16. a[i]=max(a[i],j);
  17. }
  18. }
  19. }
  20.  
  21. map<int,int> mp;
  22. for(int i=0;i<n;i++){
  23. mp[a[i]]++;
  24. }
  25. int ans=0;
  26. for(auto s:mp){
  27. int x=s.second;
  28. ans+=(x*(x-1))/2;
  29. }
  30. cout<<ans<<endl;
  31.  
  32.  
  33.  
  34. }
  35.  
  36. signed main() {
  37. int t;
  38. cin >> t;
  39. while (t--) {
  40. solve();
  41. }
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.01s 5284KB
stdin
5
5
1 4 3 7 10
3
1 1 1
4
6 2 5 3
2
2 4
1
1
stdout
1
3
2
0
0