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. ERP软件数据库覆盖数据恢复成功/重装数据库系统软件,导致同名文件覆盖

    ERP软件数据库覆盖数据恢复成功/重装数据库系统软件,导致同名文件覆盖   [数据恢复故障描述] 上海某酒店ERP软件原来安装在C盘上,用户误操作把软件进行了卸载,发现软件没有了, 但操作之前没有把原 ...

  2. Learning How to Learn, Part 1

    Jan 8, 2015 • vancexu Learning How to Learn: Powerful mental tools to help you master tough subjects ...

  3. python threading模块中对于信号的抓取

    最近的物联网智能网关(树莓派)项目中遇到这样一个问题:要从多个底层串口读取发来的数据,并且做出相应的处理,对于每个串口的数据的读取我能想到的可以采用两种方式: 一种是采用轮询串口的方式,例如每3s向每 ...

  4. 获取IE浏览器关闭事件

    //关闭浏览器时才会触发此操作,刷新页面不执行 //n 检测鼠标相对于用户屏幕的水平位置 - 网页正文部分左:求出鼠标在当前窗口上的水平位置(参照:当前窗口右上角为0.0坐标) //m 网页正文全文宽 ...

  5. Motion-Based Multiple Object Tracking

    kalman filter tracking... %% Motion-Based Multiple Object Tracking % This example shows how to perfo ...

  6. 前端制作篇之meta标签篇

    移动端前端制作有些地方不同于互联网,这篇主要讨论的是meta标签.meta标签位于之间.是主要辅助HTML结构层的.meta标签不管在互联网前端还是在移动端都起了很重要的作用.这里只讨论移动端. 附上 ...

  7. html标签默认样式整理

    引:http://www.jb51.net/web/94964.html 文为大家整理了html标签默认样式属性及浏览器默认样式等等,喜欢css布局的朋友们可以学下,希望对大家有所帮助 html, a ...

  8. 使用ProgressDialog创建进度对话框

    ProgressDialog代表了进度对话框,程序只要创建ProgressDialog实例,并将它显示出来就是一个进度对画框.使用ProgressDialog创建进度对话框有如下两种方式. ①如果只是 ...

  9. js url参数的获取和设置以及删除

    //获取url参数的值:name是参数名 function getQueryString(name) { var reg = new RegExp("(^|&)" + na ...

  10. easyUI 添加排序到datagrid

    http://www.cnblogs.com/javaexam2/archive/2012/08/10/2632645.html