Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*BISMILLAH
- THE WHITE WOLF
- NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef pair<int, int> pii;
- typedef vector<long long> vll;
- typedef vector<int> vi;
- #define io ios_base::sync_with_stdio(false)
- #define pb push_back
- #define eb emplace_back
- #define mod 998244353
- #define PI 2*acos(0.0)
- int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};
- ll bigmod(ll x, ll p)
- {
- ll res = 1;
- while(p)
- {
- if(p&1)
- res = (res*x)%mod;
- x = (x*x)%mod;
- p >>= 1;
- }
- return res;
- }
- //=============================================ASIFAZAD==============================================//
- int32_t main()
- {
- io;
- int n;
- cin>>n;
- string s;
- cin>>s;
- int cnt = 0;
- set<int> ind;
- for(int i = 0; i< n;i++)
- {
- if(s[i] == '1')
- {
- cnt++;
- ind.insert(n-1-i);
- }
- }
- vi p1(n), p2(n);
- p1[0] = 1, p2[0] = 1;
- for(int i = 1; i< n; i++)
- {
- p1[i] = p1[i-1]*2LL%(cnt+1);
- if(cnt-1)
- p2[i] = p2[i-1]*2LL%(cnt-1);
- }
- int x1 = 0, x2 = 0;
- for(auto i: ind)
- {
- x1 = (x1 + p1[i])%(cnt+1);
- if(cnt-1)
- x2 = (x2 + p2[i])%(cnt-1);
- }
- for(int i = 0; i< n;i++)
- {
- if(cnt -1 == 0 && s[i] == '1')
- {
- cout<<"0\n";
- continue;
- }
- int ac, mv = 1;
- if(s[i] == '0')
- ac = (x1 + p1[n-1-i])%(cnt+1);
- else
- ac = (x2 - p2[n-1-i] + cnt-1)%(cnt-1);
- while(ac)
- {
- bitset<30> b(ac);
- mv++;
- ac = ac%b.count();
- }
- cout<<mv<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement