fork download
  1. /*
  2. The darkest places in the hell are reserved for those who maintain thier neutrality in time of moral crisis- Bertrand Zobrist.
  3. Religion and GOD are the only shit between India and Development
  4. */
  5. #include<stdio.h>
  6. #include<iostream>
  7. #include<bitset>
  8. #include<math.h>
  9. #include<string.h>
  10. using namespace std;
  11. int array[20005], solution[20005] ;
  12. bitset <31> bin[20005] ;
  13. bitset <31> sol[20005] ;
  14. int main(){
  15. int T, N, K, ans ;
  16. scanf("%d", &T) ;
  17. while(T--){
  18. ios_base::sync_with_stdio(false); cin.tie(0) ;
  19. scanf("%d %d", &N, &K) ;
  20. for(int i = 0; i < N; i++){
  21. scanf("%d", &array[i]) ;
  22. for(int j = 0; j < 31; j++)
  23. bin[i][j] = array[i] & 1 << j ;
  24. }
  25. K = min(K, N / 2) ;
  26. int zeroes ;
  27. for(int i = 0; i < 31; i++){
  28. zeroes = 0;
  29. for(int j = 0; j < 2*K+1; j++){
  30. if (bin[j][i] == 0)
  31. zeroes++;
  32. }
  33. for (int k = 0; k < N; k++){
  34. if (!zeroes)
  35. sol[(K+k)%N][i] = 1 ;
  36. else
  37. sol[(K+k)%N][i] = 0 ;
  38.  
  39. if (bin[k][i] == 0)
  40. zeroes--;
  41.  
  42. if(bin[(2*K+1+k)%N][i] == 0)
  43. zeroes++;
  44. }
  45. }
  46. for (int i = 0; i < N; i++){
  47. ans = 0 ;
  48. for(int j = 0; j < 31; j++){
  49. ans += sol[i][j] * (pow(2,j)) ;
  50. }
  51. printf("%d ", ans);
  52. }
  53. printf("\n");
  54. }
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0s 3772KB
stdin
1
2
10
42
11
stdout
0 0