ash_sinha

243A

Sep 6th, 2022
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 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.  
  6. #define ff              first
  7. #define ss              second
  8. #define int             long long
  9. #define pb              push_back
  10. #define mp              make_pair
  11. #define pii             pair<int,int>
  12. #define vi              vector<int>
  13. #define mii             map<int,int>
  14. #define pqb             priority_queue<int>
  15. #define pqs             priority_queue<int,vi,greater<int> >
  16. #define setbits(x)      __builtin_popcountll(x)
  17. #define zrobits(x)      __builtin_ctzll(x)
  18. #define mod             1000000007
  19. #define inf             1e18
  20. #define ps(x,y)         fixed<<setprecision(y)<<x
  21. #define mk(arr,n,type)  type *arr=new type[n];
  22. #define w(x)            int x; cin>>x; while(x--)
  23. mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
  24. #define fastio          ios_base::sync_with_stdio(0); cin.tie(0);
  25. int32_t main()
  26. {
  27.     fastio;
  28.     int n;cin>>n;vi a(n);
  29.     set<int> st;
  30.     map<int,pqs> hash;
  31.     for(int i=0;i<n;i++)cin>>a[i];
  32.     for(int i=0;i<n;i++)
  33.     {
  34.         int x=a[i];
  35.         for(int j=0;j<=20;j++)
  36.         {
  37.             if((x&(1<<j))!=0) hash[j].push(i);
  38.         }
  39.     }
  40.     for(int i=0;i<n;i++)
  41.     {
  42.         int x=a[i];
  43.         st.insert(a[i]);
  44.         for(int j=0;j<=20;j++)
  45.         {
  46.             if((x&(1<<j))!=0) hash[j].pop();
  47.         }
  48.         vector<pii> b;
  49.         for(int j=0;j<=20;j++)
  50.         {
  51.             if(!hash[j].empty()) b.pb({hash[j].top(),j});
  52.         }
  53.         sort(b.begin(),b.end());
  54.         for(int j=0;j<b.size();j++)
  55.         {
  56.             x=x|(1<<(b[j].ss));
  57.             st.insert(x);
  58.         }
  59.         b.clear();
  60.     }
  61.     cout<<st.size()<<endl;
  62.    
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment