题目网址:http://codeforces.com/contest/1151/problem/C

题目大意:给定奇数集和偶数集,现构造一个数组,先取奇数集中一个元素1,再取偶数集二个元素2,4,再取奇数集四个元素3,5,7,9,再取偶数集八个元素,6,8,10……

得到 1,2,4,3,5,7,9,6,8,10,12……问这个数组的某一区间和是多少,并对1e9+7取模。

题解:对于奇数集x和偶数集y的前k项,有x=k^2,y=k*(k+1),首先,计算区间和,可以用前缀和,当计算前n项的和时,只需判断前n项有多少个奇数和偶数即可,要注意取模作差的时候可能出现负数的情况。

 #include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+;
ll cal(ll x)
{
ll odd=,even=,flag=,c=;
while(x) {
if(flag==) {
odd+=min(c,x);x-=min(x,c);
}
else {
even+=min(c,x);x-=min(x,c);
}
flag=-flag;c<<=;
}
ll ans=(odd%mod)*(odd%mod)%mod+(even%mod)*((even+)%mod)%mod;
return ans%mod;
}
int main()
{
ll l,r;
cin>>l>>r;
cout<<(cal(r)-cal(l-)+mod)%mod<<endl;
}

Codeforces Round #553 (Div. 2) C题的更多相关文章

  1. Codeforces Round #553 (Div. 2) D题

    题目网址:http://codeforces.com/contest/1151/problem/D 题目大意:给出n组数对,(ai , bi),调整这n组数对的位置,最小化 ∑(ai*( i -1)+ ...

  2. Codeforces Round #553 (Div. 2) B题

    题目网址:http://codeforces.com/contest/1151/problem/B 题目大意:给定一个n*m的矩阵,问是否可以从每一行中选择一个数,使得这n个数异或大于0,如果可以还要 ...

  3. Codeforces Round #553 (Div. 2) A题

    题目网址:http://codeforces.com/contest/1151/problem/A 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母, ...

  4. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  5. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  6. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  7. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  8. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  9. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

随机推荐

  1. Java BASE58 以及 md5,sha256,sha1

    package cn.ubibi.wsblog.utils; import java.io.UnsupportedEncodingException; import java.math.BigInte ...

  2. WinForm控件--DotNetBar--SuperGridControl

    //SuperGridControl控件初始化 private void ResetLayout(SuperGridControl SGC) { GridPanel panel = SGC.Prima ...

  3. Python-10 字典dict

    #1 创建 dict1={'欢欢':'i love','小高高':'you'} dict2={1:'one',2:'two',3:'three'} dict3={} #2 访问元素 print('欢欢 ...

  4. 部署redis4.0-cluster

    一.部署环境 .关闭iptables(firewalld)或添加放行规则 .关闭selinux3.部署redis实例,参考:https://www.cnblogs.com/panwenbin-logs ...

  5. Python 内置函数math,random

    内置函数的一些操作 - math(数学模块) - random(随机模块) - 使用内置函数时注意需要导入 math - (ceil)向上取整,返回取整数 # 向上取整,返回向上取整的数 import ...

  6. [UnityShader基础]08.UI-Default.shader

    参考链接: https://zhuanlan.zhihu.com/p/32561155 https://blog.csdn.net/WuShangLZ/article/details/80401441 ...

  7. python 之修饰器

    from functools import update_wrapper def debug(func): def wrapper(): print "[DEBUG]: enter {}() ...

  8. Zabbix监控中,使用的比较好的动作信息模板

    https://www.cnblogs.com/songxingzhu/p/7299377.html 故障{TRIGGER.STATUS},服务器:{HOSTNAME1}发生: {TRIGGER.NA ...

  9. Powser Design 16.5 导入Mysql数据库的bug

    在Power Designer 16.5中,想导入mysql的某个数据库,选择导入后会导入全部数据库. 解决方案: 打开powerdesigner.选择file--->reverse engin ...

  10. jquery中的 jquery.contains(a,b)

    jquery.contains(a,b) 判断元素 a中是否包含 b 元素: 源码: contains = isNative(docElem.contains) || docElem.compareD ...