Advertisement
THE_WHITE_WOLF

Untitled

Jul 11th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. /*BISMILLAH
  2. THE WHITE WOLF
  3. NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/
  4.  
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. typedef unsigned long long ull;
  9. typedef pair<int, int> pii;
  10. typedef vector<long long> vll;
  11. typedef vector<int> vi;
  12.  
  13. #define io ios_base::sync_with_stdio(false)
  14. #define pb push_back
  15. #define eb emplace_back
  16. #define mod   998244353
  17. #define PI 2*acos(0.0)
  18. int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};
  19.  
  20. ll bigmod(ll x, ll p)
  21. {
  22.     ll res = 1;
  23.     while(p)
  24.     {
  25.         if(p&1)
  26.             res = (res*x)%mod;
  27.         x = (x*x)%mod;
  28.         p >>= 1;
  29.     }
  30.     return res;
  31. }
  32.  
  33. //=============================================ASIFAZAD==============================================//
  34.  
  35.  
  36. int32_t main()
  37. {
  38.     io;
  39.     int n;
  40.     cin>>n;
  41.     string s;
  42.     cin>>s;
  43.     int cnt = 0;
  44.     set<int> ind;
  45.     for(int i = 0; i< n;i++)
  46.     {
  47.         if(s[i] == '1')
  48.         {
  49.             cnt++;
  50.             ind.insert(n-1-i);
  51.         }
  52.     }
  53.     vi p1(n), p2(n);
  54.     p1[0] = 1, p2[0] = 1;
  55.     for(int i = 1; i< n; i++)
  56.     {
  57.         p1[i] = p1[i-1]*2LL%(cnt+1);
  58.         if(cnt-1)
  59.             p2[i] = p2[i-1]*2LL%(cnt-1);
  60.     }
  61.     int x1 = 0, x2 = 0;
  62.     for(auto i: ind)
  63.     {
  64.         x1 = (x1 + p1[i])%(cnt+1);
  65.         if(cnt-1)
  66.             x2 = (x2 + p2[i])%(cnt-1);
  67.     }
  68.     for(int i = 0; i< n;i++)
  69.     {
  70.         if(cnt -1 == 0 && s[i] == '1')
  71.         {
  72.             cout<<"0\n";
  73.             continue;
  74.         }
  75.         int ac, mv = 1;
  76.         if(s[i] == '0')
  77.             ac = (x1 + p1[n-1-i])%(cnt+1);
  78.         else
  79.             ac = (x2 - p2[n-1-i] + cnt-1)%(cnt-1);
  80.         while(ac)
  81.         {
  82.             bitset<30> b(ac);
  83.             mv++;
  84.             ac = ac%b.count();
  85.         }
  86.         cout<<mv<<"\n";
  87.     }
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement