Valkyrie006

Untitled

Jan 26th, 2021 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. // using namespace __gnu_pbds;
  4. using namespace std;
  5. #define endl '\n'
  6. #define maxl __LONG_LONG_MAX__
  7. #define pb push_back
  8. #define F first
  9. #define S second
  10. #define rep(i, n) for (int i = 0; i < n; i++)
  11. #define rev(i, n) for (int i = n - 1; i >= 0; i--)
  12. #define rep1(i, n) for (int i = 1; i < n; i++)
  13. #define rev1(i, n) for (int i = n; i > 0; i--)
  14. #define n_ones(x) __builtin_popcountll(x)
  15. #define n_trailzero(x) __builtin_ctzll(x)
  16. #define n_leadingzero(x) __builtin_clz(x)
  17. #define sz(a) (ll)(a.size())
  18. #define all(v) v.begin(), v.end()
  19. #define FASTIO \
  20. { \
  21. ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); \
  22. }
  23. #define gcd(a, b) __gcd(a, b)
  24. #define lcm(a, b) (a / gcd(a, b)) * b
  25. #define PI 3.14159265358979323846
  26. #define see(args...) \
  27. { \
  28. cerr << "LINE " << __LINE__; \
  29. string _s = #args; \
  30. replace(_s.begin(), _s.end(), ',', ' '); \
  31. stringstream _ss(_s); \
  32. istream_iterator<string> _it(_ss); \
  33. err(_it, args); \
  34. cerr << endl; \
  35. }
  36. void err(istream_iterator<string> it)
  37. {
  38. }
  39. template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args)
  40. {
  41. cerr << ' ' << *it << " = " << a;
  42. err(++it, args...);
  43. }
  44. template <typename T, typename U> inline void min_self(T &x, U y)
  45. {
  46. if (y < x)
  47. x = y;
  48. }
  49. template <typename T, typename U> inline void max_self(T &x, U y)
  50. {
  51. if (x < y)
  52. x = y;
  53. }
  54. template <class T1, class T2> ostream &operator<<(ostream &out, pair<T1, T2> pair)
  55. {
  56. return out << "(" << pair.first << ", " << pair.second << ")";
  57. }
  58. template <class T> ostream &operator<<(ostream &out, vector<T> vec)
  59. {
  60. out << "(";
  61. for (auto &v : vec)
  62. out << v << ", ";
  63. return out << ")";
  64. }
  65. template <class T> ostream &operator<<(ostream &out, set<T> vec)
  66. {
  67. out << "(";
  68. for (auto &v : vec)
  69. out << v << ", ";
  70. return out << ")";
  71. }
  72. template <class L, class R> ostream &operator<<(ostream &out, map<L, R> vec)
  73. {
  74. out << "(";
  75. for (auto &v : vec)
  76. out << "[" << v.first << ", " << v.second << "]";
  77. return out << ")";
  78. }
  79. template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a)
  80. {
  81. return in >> a.first >> a.second;
  82. }
  83. template <class A> istream &operator>>(istream &in, vector<A> &a)
  84. {
  85. for (A &i : a)
  86. in >> i;
  87. return in;
  88. }
  89.  
  90. typedef long long int ll;
  91. typedef long double ld;
  92. typedef pair<ll, ll> pll;
  93. typedef vector<ll> vll;
  94. typedef vector<pair<ll, ll>> vpll;
  95. typedef vector<vector<ll>> vvll;
  96.  
  97. // typedef tree<int,null_type,less<int>,rb_tree_tag,
  98. // tree_order_statistics_node_update> indexed_setll;
  99. // typedef tree<char,null_type,less<char>,rb_tree_tag,
  100. // tree_order_statistics_node_update> indexed_setc;
  101.  
  102. ll max(int a, ll b)
  103. {
  104. return max((ll)a, b);
  105. }
  106. ll min(int a, ll b)
  107. {
  108. return min((ll)a, b);
  109. }
  110. ll min(ll a, int b)
  111. {
  112. return min(a, (ll)b);
  113. }
  114. ll max(ll a, int b)
  115. {
  116. return max(a, (ll)b);
  117. }
  118.  
  119. // cout<<fixed<<setprecision(20)<<pi<<endl;
  120.  
  121. ll mod = 1e9 + 7;
  122. ll Test, cas;
  123.  
  124. void solve()
  125. {
  126. int n, q;
  127. cin >> n >> q;
  128. int A[n];
  129. for (int i = 0; i < n; i++)
  130. cin >> A[i];
  131. int B[q][2];
  132. for (int i = 0; i < q; i++)
  133. cin >> B[i][0] >> B[i][1];
  134. int cnt[n + 1][31];
  135. for (int i = 0; i <= n; i++)
  136. {
  137. for (int b = 0; b <= 30; b++)
  138. {
  139. cnt[i][b] = 0;
  140. }
  141. }
  142. for (int i = 0; i < n; i++)
  143. {
  144. for (int b = 0; b <= 30; b++)
  145. {
  146. cnt[i + 1][b] = cnt[i][b];
  147. if (A[i] & (1LL << b))
  148. {
  149. cnt[i + 1][b]++;
  150. }
  151. }
  152. }
  153. int ans[q];
  154. for (int i = 0; i <= n; i++)
  155. {
  156. for (int b = 0; b <= 30; b++)
  157. {
  158. see(i, b, cnt[i][b]);
  159. }
  160. }
  161. for (int i = 0; i < q; i++)
  162. {
  163. int flag = 0;
  164. for (int b = 0; b <= 30; b++)
  165. {
  166. if (cnt[B[i][1] + 1][b] - cnt[B[i][0]][b] >= 2)
  167. {
  168. see(i, cnt[B[i][1] + 1][b], cnt[B[i][0]][b]);
  169. flag = 1;
  170. }
  171. }
  172. if (flag == 1)
  173. ans[i] = 0;
  174. else
  175. ans[i] = 1;
  176. cout << ans[i] << " ";
  177. }
  178.  
  179. return;
  180. }
  181.  
  182. int main()
  183. {
  184. FASTIO;
  185. Test = 1;
  186. // cin >> Test;
  187. for (cas = 1; cas <= Test; cas++)
  188. solve();
  189. return 0;
  190. }
Add Comment
Please, Sign In to add comment