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+ ...
随机推荐
- SimpleDateFormat 的 format 方法使用具体解释
Java中怎么才干把日期转换成想要的格式呢.或把字符串转换成一定格式的日期,如把数据库中的日期或时间转换成自己想要的格式,JAVA中提供了SimpleDateFormat类能够实现,下面是Simple ...
- wordpress安装(ubuntu+nginx+php+mariadb)
一. 环境 ubuntu12.04.4 nginx 1.6.0 mariadb 10.0 更新系统补丁 sudo apt-get update sudo apt-get dist-upgrade ...
- Objective-C 方法交换实践(三) - Aspects 源码解析
一.类与变量 AspectOptions typedef NS_OPTIONS(NSUInteger, AspectOptions) { AspectPositionAfter = 0, /// 原方 ...
- 怎样在Win7系统中搭建Web服务器
一.搭建web服务 1.打开控制面板,选择并进入“程序”,双击“打开或关闭Windows服务”,在弹出的窗口中选择“Internet信息服务”下面所有的选项,点击确定后,开始更新服务. 2.更新完成后 ...
- java业务逻辑,利用hibernate获取所连接的数据库信息
1.本人程序架构是springMVC+hibernate,这次的需求是要针对不同的数据库,做不同的处理. 2.获取所连接的数据库是什么,oracle? mysql? sql server? 基础 ...
- 淘宝商品放大镜效果-JavaScript
效果图 HTML代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- appache 端口 更改
外网访问---->hosts文件映射服务名(127.0.0.1 xiaotian.cn)-->appache中httpd文件监听相关端口号(*:8080)--->appache中的v ...
- HBase操作一
package Hbase; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.a ...
- (补题 杭电 1008)Elevator
Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Kotlin基础学习笔记(2)
1.基本数据类型 Kotlin的基本数值类型包括byte,short,int,long,float,double等.字符不属于数值类型,是一个独立的数据类型. 数字类型中不会主动转换.例如,不能给Do ...