Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define fixed(n) fixed << setprecision(n)
- #define ceil(n, m) (((n) + (m) - 1) / (m))
- #define add_mod(a, b, m) (((a % m) + (b % m)) % m)
- #define sub_mod(a, b, m) (((a % m) - (b % m) + m) % m)
- #define mul_mod(a, b, m) (((a % m) * (b % m)) % m)
- #define all(vec) vec.begin(), vec.end()
- #define rall(vec) vec.rbegin(), vec.rend()
- #define sz(x) int(x.size())
- #define debug(x) cout << #x << ": " << (x) << "\n";
- #define fi first
- #define se second
- #define ll long long
- #define ull unsigned long long
- #define EPS 1e-9
- constexpr int INF = 1 << 30, Mod = 1e9 + 7;
- constexpr ll LINF = 1LL << 62;
- #define PI acos(-1)
- template < typename T = int > using Pair = pair < T, T >;
- vector < string > RET = {"NO", "YES"};
- template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
- for (auto &x : v) in >> x;
- return in;
- }
- template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
- for (const T &x : v) out << x << ' ';
- return out;
- }
- void Solve(){
- int n;
- cin >> n;
- vector < int > vec(n), bits(32);
- cin >> vec;
- map < int, int > occ;
- ll ans = 0, l = 0, r = 0;
- auto add = [&](int x){
- for(int i = 0; i < 32; i++){
- if(x & (1 << i))
- bits[i]++;
- }
- };
- auto remove = [&](int x){
- for(int i = 0; i < 32; i++){
- if(x & (1 << i))
- bits[i]--;
- }
- };
- auto check = [&](){
- for(int i = 0; i < 32; i++){
- if(bits[i] > 1)
- return false;
- }
- return true;
- };
- while(r < n){
- add(vec[r]);
- while(l < n && !check())
- remove(vec[l++]);
- ans += r - l + 1;
- r++;
- }
- cout << ans << "\n";
- }
- int main(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int test_cases = 1;
- // cin >> test_cases;
- for(int tc = 1; tc <= test_cases; tc++){
- // cout << "Case #" << tc << ": ";
- Solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement