• Codeforces Round #553 (Div. 2) C. Problem for Nazar 模拟+思维


    题目链接
    题意:给你给无限长的序列AA,让你求出i=lrAisum_{i=l}^{r}A_i.
    思路:转化一下,即求i=1rAii=1l1Aisum_{i=1}^{r}A_i-sum_{i=1}^{l-1}A_i。那么问题就好解决了,不断的倍增加上当前段的贡献,最后去掉多余的即可。

    #include<bits/stdc++.h>
    
    #define LL long long
    #define fi first
    #define se second
    #define mp make_pair
    #define pb push_back
    
    using namespace std;
    
    const int N = 2e5 + 11;
    const LL mod = 1e9 + 7;
    LL l, r, now = 1, sta, A, B;
    LL odd, even;
    LL get(LL g)
    {
        A = B =  0;now = sta = 1;odd = even = 0;LL ans=0;
        while(1){
        	if(sta)ans+=(now/2)%mod*((B+now/2)%mod)%mod;
        	else ans+=(now/2)%mod*((A+now/2)%mod)%mod;
        	if(sta)B+=now;
        	else A+=now;
        	if(now>g)break;
        	now*=2;
        	sta^=1;
        }
        now--;
        sta^=1;
        if(sta)ans-=(now-g)%mod*((A-(now-g)+mod)%mod)%mod;
        else ans-=(now-g)%mod*((B-(now-g)+mod)%mod)%mod;
        return (ans+mod)%mod;
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin >> l >> r;
        cout << (get(r) - get(l - 1) + mod) % mod << endl;
        return 0;
    }
    
  • 相关阅读:
    OI省选知识清单
    FWT板子
    [APIO2018]选圆圈
    [APIO2018]铁人两项
    [Test-1.11]-T4 Transform
    [Test-1.11]-T2divisor
    [Test1.11]-T3对合
    [Test3.3]-T3 Sorting (卡常)
    [Test1.11]-T1匹配 Matching
    二、Unity调用Xcode封装方法
  • 原文地址:https://www.cnblogs.com/pubgoso/p/10829016.html
Copyright © 2020-2023  润新知