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. Memcached源码分析之请求处理(状态机)

    作者:Calix 一)上文 在上一篇线程模型的分析中,我们知道,worker线程和主线程都调用了同一个函数,conn_new进行事件监听,并返回conn结构体对象.最终有事件到达时,调用同一个函数ev ...

  2. jsp发布后应用根目录

    1.发布到tomcat后获取应用的根目录 ServletContext s1=this.getServletContext(); String temp=s1.getRealPath("/& ...

  3. tomcat 插件

    1. http://www.eclipsetotale.com/tomcatPlugin.html

  4. 如何让搜索引擎抓取AJAX内容? 转

    越来越多的网站,开始采用"单页面结构"(Single-page application). 整个网站只有一张网页,采用 Ajax 技术,根据用户的输入,加载不同的内容. 这种做法的 ...

  5. IOS开发-UI学习-UITabBarController的使用

    UITabBarController具体实例如下图 我们最常见的就是微信最下面的四个按钮,通过这四个按钮可以导航到不同的界面. UITabBarController是一个容器,以下的例程中给UITab ...

  6. CSS border三角、圆角图形生成技术简介

    http://www.zhangxinxu.com/wordpress/?p=794 一.前言 利用CSS的border属性可以生成一些图形,例如三角或是圆角.纯粹的CSS2的内容,没有兼容性的问题, ...

  7. python 爬照片 模拟浏览器 先登录账号

    # -*- coding: utf-8 -*-"""Created on Mon Mar 7 10:53:40 2016 @author: root"" ...

  8. jQuery初始化

    jQuery 初始化的理解 var jQuery = function( selector, context ) { // The jQuery object is actually just the ...

  9. jQuery 获取和设置type为hidden的input的值

    HTML代码 <input type="hidden" name="type" id="type" value="1&quo ...

  10. Typescript中的Class

    let btn = document.createElement('button'); btn.textContent = 'Say Hello'; document.body.appendChild ...