fork download
  1. /**
  2.  * Author: ZyadFVA
  3.  * --
  4. **/
  5.  
  6. #ifdef LOCAL
  7.  
  8. #include "algo/debug.h"
  9.  
  10. #else
  11. #define debug(...) 42
  12. #endif
  13.  
  14. #include <bits/stdc++.h>
  15.  
  16. using namespace std;
  17.  
  18. #define ll long long
  19. #define int long long
  20. const int MOD = 1e9+7;
  21.  
  22.  
  23.  
  24. void solve()
  25. {
  26.  
  27.  
  28. int q,n;
  29. cin>>q>>n;
  30.  
  31. while (q--)
  32. {
  33. int op,x;
  34. cin>>op>>x;
  35. if(op==1)
  36. {
  37. //shift n to right x times and make "AND" with 1.
  38. cout << ((n>>x)&1) <<endl;
  39. /*
  40.   * another sol
  41.   * int m = n;
  42.   * m>>=x; // shift right x times
  43.   * cout << (m&1)<<endl; // print bit value
  44.   */
  45. }
  46. else if (op==2)
  47. {
  48. //shift 1 left x times and make "OR" with n;
  49. n|= (1<<x);
  50. cout << n<<endl;
  51. /*
  52.   * another sol
  53.   * int m = 1<<x;
  54.   * n|=m;
  55.   */
  56. }
  57. else if (op==3)
  58. {
  59. // shift 1 left x times, then make "NOT" operation on it so flip all bits
  60. // then make "AND" with n;
  61. n&= ~(1<<x);
  62. cout << n<<endl;
  63. /*
  64.   * another sol
  65.   * int m = 1<<x;
  66.   * m = ~m; // flip all bits so only x-th bit be zero
  67.   * n&=m;
  68.   */
  69. }
  70. else
  71. {
  72. //shift 1 left x times and make "XOR" with n;
  73. n^= (1<<x);
  74. cout << n<<endl;
  75. /*
  76.   * another sol
  77.   * int m = 1<<x;
  78.   * n^=m;
  79.   */
  80. }
  81. }
  82.  
  83.  
  84. }
  85.  
  86. int32_t main() {
  87. ios::sync_with_stdio(false);
  88. //freopen("output.txt","w", stdout);
  89. cin.tie(nullptr);
  90. int t = 1;
  91. //cin >> t;
  92. for (int i = 1; i <= t; ++i) {
  93. solve();
  94. }
  95.  
  96. return 0;
  97. }
Success #stdin #stdout 0.01s 5280KB
stdin
6 5
1 0
1 1
1 2
2 1
3 0
4 3
stdout
1
0
1
7
6
14