Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined) C D

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cys460714380/article/details/79850070

C Subsequence Counting
http://codeforces.com/contest/960/problem/C
构造一段一段的
每一段只能跟自己这一段的数字产生贡献

int x,d;
    sdd(x,d);
    ll now = 1;
    vector<ll>v;
    while(x)
    {
        int w = 0;
        for(int i=31;i;--i)
        {
            if((1<<i)-1<=x)
            {
                w = i;
                break;
            }
        }
        int cnt = (1<<w);
        x -= cnt - 1;
        r0(i,w)v.pb(now);
        now += d;
    }
    int ans = v.size();
    ansn();
    r0(i,ans)printf("%lld ",v[i]);

D
http://codeforces.com/contest/960/problem/D
考虑当前第i层和第i-1层的偏移量
只会受cnt2[i] , cnt[i-1],cnt[i]影响 计算一下移动的距离

ll cnt[100];//pianyi
ll cnt2[100];
int main() {
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL


    int q;
    sd(q);
    while(q--) {
        int a;
        sd(a);
        if(a==1) {
            ll x;
            sld(x);
            ll k;
            sld(k);
            int w  = 0;
            ll tmp = x;
            while(tmp)w++,tmp>>=1;
            ll m = 1LL<<(w-1);
            k = (k%m+m)%m;
            cnt[w] += k;
            cnt[w] %= m;
        } else if(a==2) {
            ll x;
            sld(x);
            ll k;
            sld(k);
            int w  = 0;
            ll tmp = x;
            while(tmp)w++,tmp>>=1;
            ll m = 1LL<<(w-1);
            k = (k%m+m)%m;
            cnt2[w] += k;
            cnt2[w] %= m;
        } else {
            ll x;
            sld(x);
            while(x) {
                int w = 0;
                ll tmp = x;
                printf("%lld ",x);
                if(x==1)break;
                while(tmp)++w,tmp>>=1;
                ll m = 1LL<<(w-2);
                ll l = 1LL<<(w-2);
                ll mve = x/2 - l;
                ll t = -cnt[w-1]%m + ((cnt2[w]+cnt[w]+(x&1))/2)%m;
                t = (t+m)%m;
//                t += (cnt[w] +(x&1))/2%m;
                t %=m ;
                t = (t + m ) %m;
                mve = (mve + t) %m;
                x = l + mve;

            }
            puts("");
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/cys460714380/article/details/79850070