Codeforces Round #553 (Div. 2) C
1 second
256 megabytes
standard input
standard output
Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task.
Consider two infinite sets of numbers. The first set consists of odd positive numbers (1,3,5,7,…), and the second set consists of even positive numbers (2,4,6,8,…). At the first stage, the teacher writes the first number on the endless blackboard from the first set, in the second stage — the first two numbers from the second set, on the third stage — the next four numbers from the first set, on the fourth — the next eight numbers from the second set and so on. In other words, at each stage, starting from the second, he writes out two times more numbers than at the previous one, and also changes the set from which these numbers are written out to another.
The ten first written numbers: 1,2,4,3,5,7,9,6,8,10. Let's number the numbers written, starting with one.
The task is to find the sum of numbers with numbers from ll to rr for given integers ll and rr. The answer may be big, so you need to find the remainder of the division by 1000000007 (109+7).
Nazar thought about this problem for a long time, but didn't come up with a solution. Help him solve this problem.
The first line contains two integers ll and rr (1≤l≤r≤1018) — the range in which you need to find the sum.
Print a single integer — the answer modulo 1000000007 (109+7).
1 3
7
5 14
105
88005553535 99999999999
761141116
In the first example, the answer is the sum of the first three numbers written out (1+2+4=7).
In the second example, the numbers with numbers from 5 to 14: 5,7,9,6,8,10,12,14,16,18. Their sum is 105.
链接: http://codeforces.com/contest/1151/problem/C
赛后补题。
题意:给你一个无穷的数列 数列的第一部分长度为 1 ,由(1)组成、第二部分长度是2,由 (2 4) 组成、第三部分长度为4 由(3 5 7 9)组成,接下来的还是同样的规律:长度*2 奇偶互换。 求[l,r]这个区间的区间和。
常规的区间操作 【l,r】 = 【1,r】- 【1,l-1】
枚举每个子区间,统计出来奇数和偶数的个数,然后就是等差数列求和。
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long const ll mod = 1e9+;
ll solve(ll x){
ll cnt[] = {,};
int k = ;// 记录奇偶位
ll c = ; // 记录区间的长度
while(x){
cnt[k] += min(c,x);
// 当最后的那个区间长度小于 2^(n-1) (n是区间的个数) 时
// 才会 cnt[k] += x;
x -= min(c,x);
k^=;
c <<= ;
}
ll sum = (cnt[]%mod)*(cnt[]%mod)%mod;
sum += (cnt[]%mod)*((cnt[]+)%mod)%mod;
return sum%mod;
} int main(){
ll l, r;
scanf("%I64d%I64d",&l,&r);
printf("%I64d\n",(solve(r)-solve(l-)+mod)%mod);
return ;
}
Codeforces Round #553 (Div. 2) C的更多相关文章
- Codeforces Round #553 (Div. 2) D题
题目网址:http://codeforces.com/contest/1151/problem/D 题目大意:给出n组数对,(ai , bi),调整这n组数对的位置,最小化 ∑(ai*( i -1)+ ...
- Codeforces Round #553 (Div. 2) C题
题目网址:http://codeforces.com/contest/1151/problem/C 题目大意:给定奇数集和偶数集,现构造一个数组,先取奇数集中一个元素1,再取偶数集二个元素2,4,再取 ...
- Codeforces Round #553 (Div. 2) B题
题目网址:http://codeforces.com/contest/1151/problem/B 题目大意:给定一个n*m的矩阵,问是否可以从每一行中选择一个数,使得这n个数异或大于0,如果可以还要 ...
- Codeforces Round #553 (Div. 2) A题
题目网址:http://codeforces.com/contest/1151/problem/A 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母, ...
- Codeforces Round #553 (Div. 2) E 贡献
https://codeforces.com/contest/1151/problem/E 题意 一条长n的链,每个点上有值\(a[i]\),定义\(f(l,r)\)为该区间的\(值\)所代表的点留下 ...
- Codeforces Round #553 (Div. 2) C 等差数列求和 + 前缀和
https://codeforces.com/contest/1151/problem/C 题意 有两个等差数列(1,3,5,..),(2,4,6,...),两个数列轮流取1,2,4,...,\(2^ ...
- Codeforces Round #553 (Div. 2)
传送门 A. Maxim and Biology 题意: 给出一个串s,问最少需要多少步操作使得串s包含"ACTG"这个子串,输出最少操作次数: 题解: 枚举每个位置 i,求出将 ...
- Codeforces Round #553 (Div. 2) C. Problem for Nazar 数学
题意:从奇数列 1 3 5 7 9 .... 偶数列2 4 6 8 10...分别轮流取 1 2 4 ....2^n 个数构成新数列 求新数列的区间和 (就一次询问) 思路:首先单次区间和就是一个简 ...
- Codeforces Round #553 (Div. 2) D. Stas and the Queue at the Buffet 贪心+公式转化
题意 给出n个pair (a,b) 把它放在线性序列上 1--n 上 使得 sum(a*(j-1)+b*(n-j)) 最小 思路 :对式子进行合并 同类项 有: j*(a-b)+ (-a+ ...
随机推荐
- HBase可靠性管理方法浅析
HBase是一个可以进行实时读和写操作的分布式NoSQL系统,建立在HDFS之上,是Hadoop生态圈中重要的一部分.在HBase中底层存储结构采用的LSM-tree的方式进行处理,为了保证HBase ...
- #leetcode刷题之路25- k个一组翻转链表
给出一个链表,每 k 个节点一组进行翻转,并返回翻转后的链表.k 是一个正整数,它的值小于或等于链表的长度.如果节点总数不是 k 的整数倍,那么将最后剩余节点保持原有顺序. 示例 :给定这个链表:1- ...
- mysql 常用的时间日期函数小结
本文主要是总结一些常用的在实际运用中常用的一些mysql时间日期以及转换的函数 1.now() :返回当前日期和时间 select now(); //2018-04-21 09:19:21 2.cu ...
- Rabbitmq(三)
1.在服务器安装好rabbitmq后,自己配置自己用的vhost,exchange和queue的绑定 2.项目添加RabbitMqClient.dll(nuget获取)引用 3.添加helper就可以 ...
- 微信小游戏websocket支持https/wss
公司新项目需要支持wss,解决方法如下: https://blog.csdn.net/peter_teng/article/details/82866613 proxy_pass http://web ...
- 基于OpenCV的微信跳一跳外挂
摘要:微信跳一跳是时下热门的微信小游戏,基本原理是根据按压屏幕的时间控制棋子跳过的距离,使其跳到下一个方块上:现利用Android adb工具,PC端获取实时截图,使用OpenCV库分析图片计算距离, ...
- 在客户端模拟调用srv和topic
rostopic pub -r 10 /toipic_name Tab+Tab rosservice call /service_name Tab+Tab rostopic pub -r 10 /c ...
- 记数据结构MOOC-二叉树
主要的学习内容 在本章中,主要学习了二叉树的实现以及各种遍历的方法.着重介绍了前序.中序.后序三种遍历方法的递归实现,同时也描述了前序中序遍历的迭代方法. 教材的主要内容 教材是以哈夫曼编码树为主要脉 ...
- [转载]DotNetty 学习
[转载]http://www.cnblogs.com/littlegod/p/7699482.html DotNetty的学习是带着如下这些问题展开: 1. Socket基础框架方案: 通信模式:异步 ...
- 20155213 2016-2017-2 《Java程序设计》第二周学习总结
20155213 2016-2017-2 <Java程序设计>第二周学习总结 教材学习内容总结 关于Unicode和UTF 很抱歉,没能读完娄老师推荐的网址,关于Unicode和UTF的介 ...