fork download
  1. // (***** بسم الله الرحمن الرحيم ******)
  2. #include <iostream>
  3. #include <bits/stdc++.h>
  4. #include <string>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <vector>
  8. #include <map>
  9. #include <stack>
  10. #include <queue>
  11. #include <set>
  12. #define ll long long
  13. #define endl '\n'
  14. #define du double
  15. #define mx INT_MIN
  16. #define mn INT_MAX
  17. #define all(v) (v).begin(), (v).end()
  18. #define rall(v) (v).rbegin(), (v).rend()
  19. using namespace std;
  20. bool Prime(ll n) // 2 3 5 7 11 ..
  21. {
  22. if (n < 2 || (n % 2 == 0 && n != 2))
  23. {
  24. return false;
  25. }
  26. for (int i = 3; i <= sqrt(n); i += 2) // 3 5 7 9 11 ect..
  27. {
  28. if (n % i == 0)
  29. {
  30. return false;
  31. }
  32. }
  33. return true;
  34. }
  35. bool pliand(ll n) // 121 the start of number like end!!
  36. {
  37. ll num = n;
  38. ll nm = 0;
  39. for (ll i = 0; i < n;)
  40. {
  41. nm = nm * 10 + n % 10;
  42. n /= 10;
  43. }
  44. if (nm == num)
  45. {
  46. return true;
  47. }
  48. return false;
  49. }
  50. string binry_conv(ll n) // from dec like = 1 , 5 , 10 .. ect >> bainary like "0011001001"
  51. {
  52. string s;
  53. while (n)
  54. {
  55. if (n % 2 != 0)
  56. {
  57. s += '1';
  58. }
  59. else
  60. {
  61. s += '0';
  62. }
  63. n /= 2;
  64. }
  65. return s;
  66. }
  67. ll GCD(ll a, ll b) // GREATEST COMMON DIVISOR
  68. {
  69. return (!b ? a : GCD(b, a % b));
  70. }
  71. ll LCM(ll a, ll b)
  72. {
  73. return (a * b) / __gcd(a, b);
  74. }
  75. ll numofdivisors(ll n)
  76. {
  77. ll cot = 0;
  78. for (ll i = 1; i <= sqrt(n); i++)
  79. {
  80. if (n % i == 0)
  81. {
  82. cot += i;
  83. }
  84. }
  85. return cot;
  86. }
  87.  
  88. ll summmtion(ll n) // ARTIMITIC PROGRESSION
  89. {
  90. return n * (n + 1) / 2;
  91. }
  92. ll nCr(ll n, ll r) // !(n) / !(n - r)
  93. {
  94. ll p = 1, k = 1;
  95. if (n - r < r)
  96. r = n - r;
  97. if (n < 0)
  98. return 0;
  99. while (r)
  100. {
  101. p *= n; //!(n)
  102. k *= r; //!(r)
  103. ll m = GCD(p, k);
  104. p /= m;
  105. k /= m;
  106. n--;
  107. r--;
  108. }
  109. return p;
  110. }
  111. ll bianarry_search(vector<ll> v, ll st, ll end, ll target)
  112. {
  113. // order O(log(n))
  114. ll cot = 0;
  115. while (st >= end)
  116. {
  117. ll mid = (st + end) / 2;
  118. if (v[mid] > target)
  119. {
  120. st = mid + 1;
  121. }
  122. else if (v[mid] < target)
  123. {
  124. end = mid - 1;
  125. }
  126. else
  127. {
  128. return mid;
  129. // foundddd
  130. }
  131. }
  132. return -1; // not foundddd
  133. }
  134. bool isvowel(char x)
  135. {
  136. if (x == 'A' || x == 'E' || x == 'O' || x == 'Y' || x == 'U' || x == 'I')
  137. {
  138. return 1;
  139. }
  140. return 0;
  141. }
  142. //_______________| THAT'S MY COOOOOODE |_;
  143. void MEDO()
  144. {
  145. ll q, n;
  146. cin >> q >> n;
  147. while (q--)
  148. {
  149. ll type;
  150. cin >> type;
  151. if (type == 1)
  152. {
  153. ll x;
  154. cin >> x;
  155. string c;
  156. c = binry_conv(n);
  157. cout << c[x] << endl;
  158. }
  159. else if (type == 2)
  160. {
  161. ll x;
  162. cin >> x;
  163. string c;
  164. c = binry_conv(n);
  165. c[x] = '1';
  166. ll num = 0;
  167. for (int i = 0; i < n; i++)
  168. {
  169. if (c[i] == '1')
  170. {
  171. num += pow(2, i);
  172. }
  173. }
  174. n = num;
  175. cout << n << endl;
  176. }
  177. else if (type == 3)
  178. {
  179. ll x;
  180. cin >> x;
  181. string c;
  182. c = binry_conv(n);
  183. c[x] = '0';
  184. ll num = 0;
  185. for (int i = 0; i < n; i++)
  186. {
  187. if (c[i] == '1')
  188. {
  189. num += pow(2, i);
  190. }
  191. }
  192. n = num;
  193. cout << n << endl;
  194. }
  195. else
  196. {
  197. ll x;
  198. cin >> x;
  199. string c;
  200. c = binry_conv(n);
  201. if (c[x] == '1')
  202. {
  203. c[x] = '0';
  204. ll num = 0;
  205. for (int i = 0; i < n; i++)
  206. {
  207. if (c[i] == '1')
  208. {
  209. num += pow(2, i);
  210. }
  211. }
  212. n=num;
  213. cout << n << endl;
  214. }
  215. else
  216. {
  217. c[x] = '1';
  218. ll num = 0;
  219. for (int i = 0; i < n; i++)
  220. {
  221. if (c[i] == '1')
  222. {
  223. num += pow(2, i);
  224. }
  225. }
  226. n=num;
  227. cout << n << endl;
  228. }
  229. }
  230. }
  231. }
  232. void SPEED()
  233. {
  234. ios_base::sync_with_stdio(false);
  235. cin.tie(nullptr), cout.tie(nullptr);
  236. }
  237. int main()
  238. {
  239. SPEED();
  240. MEDO();
  241. }
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
Standard output is empty