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+ ...
随机推荐
- iOS开发Mac配置(CocoaPods、SourceTree、ssh key)
作为开发,有一个自己的饭碗还是有必要的.因为交接旧电脑的时候,你会遇到了一些问题,而自己的电脑就方便很多了. 要开发,当然要装一些与开发相关的东西,那么新电脑入手,要做些什么呢? 1.安装Xcode: ...
- Java并发编程(二)创建线程的三种方法
进程与线程 1. 进程 进程和代码之间的关系就像音乐和乐谱之间的关系一样,演奏结束的时候音乐就不存在了但乐谱还在:程序执行结束的时候进程就消失了但代码还在,而计算机就是代码的演奏家. 2. 线程 线 ...
- MySql多表关联,根据某列取前N条记录问题
近来遇到一个问题:“MySql多表关联,根据某列取前N条记录”. 刚开始一直在想,SQL语句是否可以做到直接查询出来,但几经折磨,还是没能写出SQL语句,-------如果有大牛的话,望指点迷津.我把 ...
- Mysql-多表连接的操作和用法
一 .介绍 二 .多表连接查询 三 .符合条件连接查询 四 .子查询 一.介绍 本节主题 多表连接查询 复合条件连接查询 子查询 准备表 #建表 create table dep( id int, n ...
- 【python 虚拟环境 virtualenv的配置】
该目录内生成一个虚目录: #运行activcate下的shell脚本,激活虚拟环境 #pip python包管理器
- vue-cli 3.0 豆瓣api接口使用element做分页
记录自己的学习 大佬绕道谢谢! 豆瓣即将上映接口:https://api.douban.com/v2/movie/coming_soon 本地跨域问题 看我之前的文章:https://www.cnbl ...
- python列表学习
#创建列表,通过[]来创建列表my_list=[] #创建了一个空列表#print(my_list,type(my_list)) #列表追存储的数据,我们称为元素#一个列表中可以存储多个元素,也可以在 ...
- leetcode记录-反转整数
给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 注意: 假 ...
- 第三次随笔——虚拟机及Linux入门
虚拟机及Linux入门 虚拟机的安装 对于虚拟机的概念我早有接触,但是从来没有真正的实践过,借这次作业机会我终于实践了虚拟机的安装,安装的过程较为顺利,但还是出现了以下问题: 无法选择64位的系统 解 ...
- Ubuntu genymotion
官网注册帐号 下载genymotion-[VERSION]_[ARCH].bin 进入android studio In Android Studio, go to File > Setting ...