Advertisement
7oSkaaa

A

Feb 24th, 2023
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define fixed(n) fixed << setprecision(n)
  6. #define ceil(n, m) (((n) + (m) - 1) / (m))
  7. #define add_mod(a, b, m) (((a % m) + (b % m)) % m)
  8. #define sub_mod(a, b, m) (((a % m) - (b % m) + m) % m)
  9. #define mul_mod(a, b, m) (((a % m) * (b % m)) % m)
  10. #define all(vec) vec.begin(), vec.end()
  11. #define rall(vec) vec.rbegin(), vec.rend()
  12. #define sz(x) int(x.size())
  13. #define debug(x) cout << #x << ": " << (x) << "\n";
  14. #define fi first
  15. #define se second
  16. #define ll long long
  17. #define ull unsigned long long
  18. #define EPS 1e-9
  19. constexpr int INF = 1 << 30, Mod = 1e9 + 7;
  20. constexpr ll LINF = 1LL << 62;
  21. #define PI acos(-1)
  22. template < typename T = int > using Pair = pair < T, T >;
  23. vector < string > RET = {"NO", "YES"};
  24.  
  25. template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
  26.     for (auto &x : v) in >> x;
  27.     return in;
  28. }
  29.  
  30. template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
  31.     for (const T &x : v) out << x << ' ';
  32.     return out;
  33. }
  34.  
  35. void Solve(){
  36.     int n;
  37.     cin >> n;
  38.     vector < int > vec(n), bits(32);
  39.     cin >> vec;
  40.     map < int, int > occ;
  41.     ll ans = 0, l = 0, r = 0;
  42.     auto add = [&](int x){
  43.         for(int i = 0; i < 32; i++){
  44.             if(x & (1 << i))
  45.                 bits[i]++;
  46.         }
  47.     };
  48.     auto remove = [&](int x){
  49.         for(int i = 0; i < 32; i++){
  50.             if(x & (1 << i))
  51.                 bits[i]--;
  52.         }
  53.     };
  54.     auto check = [&](){
  55.         for(int i = 0; i < 32; i++){
  56.             if(bits[i] > 1)
  57.                 return false;
  58.         }
  59.         return true;
  60.     };
  61.     while(r < n){
  62.         add(vec[r]);
  63.         while(l < n && !check())
  64.             remove(vec[l++]);
  65.         ans += r - l + 1;
  66.         r++;
  67.     }
  68.     cout << ans << "\n";
  69. }
  70.  
  71. int main(){
  72.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  73.     int test_cases = 1;
  74.     // cin >> test_cases;
  75.     for(int tc = 1; tc <= test_cases; tc++){
  76.         // cout << "Case #" << tc << ": ";
  77.         Solve();
  78.     }
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement