fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. void fileIO()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10. #ifndef ONLINE_JUDGE
  11. freopen("E:\\Codes\\PS codes\\JUST\\input.txt", "r", stdin);
  12. freopen("E:\\Codes\\PS codes\\JUST\\output.txt", "w", stdout);
  13. #endif
  14. }
  15.  
  16. void Striker()
  17. {
  18. int n;
  19. cin >> n;
  20. int a[n];
  21. set<int> s[10];
  22. for (int i = 0; i < n; i++)
  23. {
  24. cin >> a[i];
  25. for (int bit = 0; bit < 10; bit++)
  26. if (a[i] >> bit & 1)
  27. s[bit].insert(i);
  28. }
  29. long long ans[1024]{};
  30. for (int i = 0; i < n; i++)
  31. {
  32. int curOr = 0;
  33. int curIdx = i;
  34. while (curIdx < n)
  35. {
  36. curOr |= a[curIdx];
  37. int mn = n;
  38. for (int bit = 0; bit < 10; bit++)
  39. {
  40. if (curOr >> bit & 1)
  41. continue;
  42. auto it = s[bit].lower_bound(i);
  43. if (it != s[bit].end())
  44. mn = min(mn, *it);
  45. }
  46. ans[curOr] += (mn - curIdx);
  47. curIdx = mn;
  48. }
  49. }
  50. int q;
  51. cin >> q;
  52. while (q--)
  53. {
  54. int x;
  55. cin >> x;
  56. if (x >= 1024)
  57. cout << "0\n";
  58. else
  59. cout << ans[x] << "\n";
  60. }
  61. }
  62.  
  63. signed main()
  64. {
  65. fileIO();
  66. int _t = 1;
  67. // cin >> _t;
  68. for (int i = 0; i < _t; ++i)
  69. {
  70. Striker();
  71. }
  72. }
  73.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty