B. Code For 1
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility.

Initially Sam has a list with a single element n. Then he has to perform certain operations on this list. In each operation Sam must remove any element x, such that x > 1, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.

Now the masters want the total number of 1s in the range l to r (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test?

Input

The first line contains three integers n, l, r (0 ≤ n < 250, 0 ≤ r - l ≤ 105, r ≥ 1, l ≥ 1) – initial element and the range l to r.

It is guaranteed that r is not greater than the length of the final list.

Output

Output the total number of 1s in the range l to r in the final sequence.

Examples
Input
7 2 5
Output
4
Input
10 3 10
Output
5
Note

Consider first example:

Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.

For the second example:

Elements on positions from 3-rd to 10-th in list is [1, 1, 1, 0, 1, 0, 1, 0]. The number of ones is 5.

题目链接:http://codeforces.com/contest/768/problem/B

分析:二分的模版题!来围观看看!

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, l, r, s = , ans;
void solve(ll a, ll b, ll l, ll r, ll d)//二分的思想
{
if ( a > b || l > r ) return;
else
{
ll mid = (a+b)/;
if ( r < mid )solve(a,mid-,l,r,d/);
else if ( mid < l )solve(mid+,b,l,r,d/);
else {
ans += d%;
solve(a,mid-,l,mid-,d/);
solve(mid+,b,mid+,r,d/);
}
}
}
int main()
{
cin >> n >> l >> r;
long long p = n;
while ( p >= )
{
p /= ;
s = s*+;
}
solve(,s,l,r,n);
cout << ans << endl;
return ;
}

Codeforces 768B Code For 1的更多相关文章

  1. Codeforces 768B - Code For 1(分治思想)

    768B - Code For 1 思路:类似于线段树的区间查询. 代码: #include<bits/stdc++.h> using namespace std; #define ll ...

  2. Codeforces Avito Code Challenge 2018 D. Bookshelves

    Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...

  3. Codeforces 768B B. Code For 1

    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6423483.html B. Code For 1 time limit per test:2 se ...

  4. 【codeforces 768B】Code For 1

    [题目链接]:http://codeforces.com/contest/768/problem/B [题意] 一开始给你一个数字n; 让你用这个数字n根据一定的规则生成序列; (如果新生成的序列里面 ...

  5. Codeforces Zepto Code Rush 2014 -C - Dungeons and Candies

    这题给的一个教训:Codeforces没有超时这个概念.本来以为1000*(1000+1)/2*10*10要超时的.结果我想多了. 这题由于k层都可能有关系,所以建一个图,每两个点之间连边,边权为n* ...

  6. Codeforces - Avito Code Challenge 2018

    Portal A. Antipalindrome 暴力. B. Businessmen Problems 暴力. C. Useful Decomposition 居然不是C打头的?! 将一棵树划分成若 ...

  7. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)

    传送门 Description You are given names of two days of the week. Please, determine whether it is possibl ...

  8. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)

    传送门 Description You are given a table consisting of n rows and m columns. Numbers in each row form a ...

  9. CodeForces ZeptoLab Code Rush 2015

    拖了好久的题解,想想还是补一下吧. A. King of Thieves 直接枚举起点和5个点之间的间距,进行判断即可. #include <bits/stdc++.h> using na ...

随机推荐

  1. S3C2440启动代码2440init.s彻底解析

    可以选择nand启动和nor启动,这两者之间的关系通过一个按键来选择 这个OM0有何玄机,在数据手册中有这么一段 位宽RAM启动了(当然,还得设置一些东西,下面就说), Nanaflash启动经历的过 ...

  2. angular登录状态检查

    待补充!!!!!!!!!!! 参加链接: http://www.brafox.com/post/2015/javascript/angularjs/angularjs-router-intercept ...

  3. Linux_System2

    1.从服务器下载http*.tar.gz源码包,安装到/usr/local/apache目录下,要求安装时指定能够动态加载模块,能够支持地址回写功能,能够使用ssl加密功能../configure — ...

  4. bzoj1121

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1121 题解: 神题啊,妈的不会写的都去吃屎吧.

  5. UVa 11129 - An antiarithmetic permutation

    题目大意:给一个正整数n,构造一个0...n-1的排列,使得这个排列的任何一个长度大于2的子序列都不为等差数列. 把序列按照奇偶位置分成两个序列,这样在两个序列间就不会形成等差数列了,然后再对这两个序 ...

  6. 优酷、YouTube、Twitter及JustinTV几个视频网站的架构

      优酷视频网站架构 一.网站基本数据概览据2010年统计,优酷网日均独立访问人数(uv)达到了8900万,日均访问量(pv)更是达到了17亿,优酷凭借这一数据成为google榜单中国内视频网站排名最 ...

  7. OC--初始化UINavigationController

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...

  8. Add Strings Leetcode

    Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2 ...

  9. 浅谈Java分页技术

    话不多言.我们要实现java分页技术,我们首先就需要定义四个变量,他们是: int  pageSize;//每页显示多少条记录 int pageNow;//希望现实第几页 int pageCount; ...

  10. 选择排序法-java详解案例

    /**  * 功能:选择排序法 * 思想:第一次从R[0]-R[N-1]中选取最小值,与R[0]交换,第二次从R[1]-R[N-1]中选取最小值,与R[1]交换, * 第三次从R[2]-R[N-1]中 ...