Codeforces Round #553 (Div. 2) C题
题目网址: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题的更多相关文章
- 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) 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 #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- 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 ...
- 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 ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
随机推荐
- java Base36 算法
package com.github.linushp.wsblog.utils; import java.math.BigInteger; import java.nio.charset.Charse ...
- JSP——文件上传
Web应用中,文件的上传是很常见的功能,今天在此记录下所学的感悟吧. 实现Web应用中文件的上传需要用到的核心组件是Commen-fileUpload,组件, 但还需要Common-IO组件的支持.可 ...
- day1--一个简单的登录接口
_usrename = "Yvan"_password = "abc123"count=0while count <3: username = in ...
- 应用程序嵌入PowerBI报表登陆认证问题解决
https://github.com/AzureAD/azure-activedirectory-library-for-java/issues/144
- On-die termination for DDR
本文转载自: https://blog.csdn.net/weixin_38233274/article/details/81016870 ODT是什么鬼?为什么要用ODT?在很多关于DDR3的博文和 ...
- hive 表新增字段后更新分区无法显示数据
解决方案: 1.删除分区后重新跑数据 alter table drop partition(分区字段=“”): 2.新增字段运行程序后其实数据已经有了,只是查询hive的时候无法显示出来, 这个时候只 ...
- Spring 回滚事务@Transactional
@Transactional spring 事务注解 默认遇到throw new RuntimeException("...");会回滚 需要捕获的throw new Exce ...
- 214. Spring Security:概述
前言 在之前介绍过了Shiro之后,有好多粉丝问SpringSecurity在Spring Boot中怎么集成.这个系列我们就和大家分享下有关这方面的知识. 本节大纲 一.什么是SpringSecur ...
- Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdb ...
- zk hdfs hadoop yarn hive 学习笔记
如图