Advertisement
het_fadia

Untitled

Sep 20th, 2022
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. t=int(input())
  2. for i in range(t):
  3. n=int(input())
  4. arr=[int(i) for i in input().split()] # input arr
  5. maxn=10**5 # maximum element in the array
  6. max_bits=maxn.bit_length()
  7. negator=2**max_bits-1 # used to reverse a number
  8. ans=[0 for i in range(2*maxn+100)]
  9. def fun(s):
  10. if ans[s]==0:
  11. ans[s]=1
  12. for i in range(max_bits):
  13. if (1<<i)&s:
  14. fun(s^(1<<i))
  15. for i in arr:
  16. fun(i^negator) # flips all the bits in a number until number of bits in 10**5
  17.  
  18. print(*[ans[i] for i in arr])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement