fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. void solve(){
  16. int n;
  17. cin >> n;
  18.  
  19. vector<int>v(n);
  20.  
  21. map<int,int>freq;
  22.  
  23. for(int i = 0; i < n; i++){
  24. cin >> v[i];
  25. freq[v[i]]++;
  26. }
  27.  
  28. int frequent = 0;
  29. for(auto &p : freq){
  30. frequent = max(frequent , p.second);
  31. }
  32.  
  33. int ops = n - frequent;
  34.  
  35. while(frequent < n){
  36. frequent *= 2;
  37. ops++;
  38. }
  39.  
  40. cout << ops << '\n';
  41. }
  42.  
  43.  
  44. signed main(){
  45. FastIO();
  46.  
  47. int t = 1;
  48. cin >> t;
  49.  
  50. while (t--){
  51. solve();
  52. }
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 5320KB
stdin
6
1
1789
6
0 1 3 3 7 0
2
-1000000000 1000000000
4
4 3 2 1
5
2 5 7 6 3
7
1 1 1 1 1 1 1
stdout
0
6
2
5
7
0