fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. class Solution {
  5. static class Fast {
  6.  
  7. Fast() throws IOException {
  8. st = new StringTokenizer(br.readLine());
  9.  
  10. }
  11.  
  12. String next() throws IOException {
  13. return (st.hasMoreElements() ? st.nextToken() : (st = new StringTokenizer(br.readLine())).nextToken());
  14. }
  15.  
  16. int nextInt() throws IOException {
  17. return Integer.parseInt(next());
  18. }
  19.  
  20. long nextLong() throws IOException {
  21. return Long.parseLong(next());
  22. }
  23.  
  24. void print(Object o) throws IOException {
  25. String s = String.valueOf(o);
  26. bw.write(s);
  27. bw.flush();
  28. }
  29. }
  30.  
  31. public static void main(String args[]) throws IOException {
  32. Fast f=new Fast();
  33. int t=f.nextInt();
  34. while(t--!=0){
  35. int n=f.nextInt();
  36. int arr[]=new int[n];
  37. int max=0;
  38. for(int i=0;i<n;i++)
  39. {
  40. arr[i]=f.nextInt();
  41. if(arr[i]<0){
  42. int bilen=Integer.toBinaryString(-arr[i]).length();
  43. arr[i]=(((1<<2)-1)&arr[i]);
  44. }
  45. max=arr[i]>max?arr[i]:max;
  46. }
  47. int size=Integer.toBinaryString(max).length();
  48. ArrayList<Integer> list=new ArrayList<>();
  49. for(int i=0;i<size;i++)
  50. {
  51. int count=0;
  52. for(int j=0;j<n;j++){
  53. if(((arr[j]>>i)&1)==1)
  54. {
  55. count++;
  56. }
  57. }
  58. // System.out.println(count);
  59. list.add(count);
  60. }
  61. for(int i=list.size()-1;i>=0;i--){
  62. f.print(list.get(i) + " ");
  63. }
  64. System.out.println();
  65. }
  66. }
  67. }
Success #stdin #stdout 0.12s 51996KB
stdin
2
5
17 2 5 9 8
7
2 1 5 3 4 2 5
stdout
1 2 1 1 3 
3 3 4