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 nlr (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:

这个题目做的挺漂亮嘛!哈哈!

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iostream>
#define MAXN 200009
#define eps 1e-11 + 1e-12/2
typedef long long LL; using namespace std;
/*
显然!分治!
*/
LL n, l ,r;
LL solve(LL x, LL beg,LL end)
{
LL mid = (beg + end) / ;
if (beg == mid) return ;
if (r < mid)
return solve(x / , beg, mid - );
else if (l > mid)
return solve(x / , mid + , end);
else
{
LL ret = x % ;
if (l < mid) ret += solve(x / , beg, mid - );
if (r > mid) ret += solve(x / , mid + , end);
return ret;
}
return ;
}
int main()
{ cin >> n >> l >> r;
if (n == )
{
cout << << endl;
return ;
}
LL len = pow(, floor(log2(n)) + ) - ;
cout << solve(n, , len) << endl;
}

B. Code For 1 分治的更多相关文章

  1. code for 1 - 分治

    2017-08-02 17:23:14 writer:pprp 题意:将n分解为n/2, n%2, n/2三部分,再将n/2分解..得到一个序列只有0和1,给出[l, r]问l到r有几个1 题解:分治 ...

  2. BZOJ 2244: [SDOI2011]拦截导弹 (CDQ分治 三维偏序 DP)

    题意 略- 分析 就是求最长不上升子序列,坐标取一下反就是求最长不下降子序列,比较大小是二维(h,v)(h,v)(h,v)的比较.我们不看概率,先看第一问怎么求最长不降子序列.设f[i]f[i]f[i ...

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

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

  4. Code Chef TSUM2(动态凸包+点分治)

    题面 传送门 题解 真是毒瘤随机化算法居然一分都不给 首先这种树上的题目一般想到的都是点分 我们考虑如何统计经过当前点的路径的贡献,设当前点\(u\)在序列中是第\(c\)个,那么一条路径的贡献就是 ...

  5. CodeForces768B:Code For 1 (分治)

    Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On hi ...

  6. HDU5618 & CDQ分治

    Description: 三维数点 Solution: 第一道cdq分治...感觉还是很显然的虽然题目不能再傻逼了... Code: /*=============================== ...

  7. 【Codeforces715C&716E】Digit Tree 数学 + 点分治

    C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...

  8. 【BZOJ-4456】旅行者 分治 + 最短路

    4456: [Zjoi2016]旅行者 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 254  Solved: 162[Submit][Status] ...

  9. 【BZOJ-3262】陌上花开 CDQ分治(3维偏序)

    3262: 陌上花开 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1439  Solved: 648[Submit][Status][Discuss ...

随机推荐

  1. Windows 使用之那些你还不知道操作

    作者:你未读 整理:君未读 关于使用 win 系统的基本普及. 建议更换 win10 系统 可能很多朋友看到这个建议,心里很不爽,还很不服气,别急,且看官方给出的信息. 也就是说在 2019 年你完全 ...

  2. [Offer收割]编程练习赛84 -- 括号序列

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个只包含'(', ')'和''的字符串S,现在小Hi可以任意指定''为'('或')',不同的'*'可以是不同的字符. ...

  3. hdu5922Minimum’s Revenge

    Minimum's Revenge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  4. 【转载】 python sort、sorted高级排序技巧

    这篇文章主要介绍了python sort.sorted高级排序技巧,本文讲解了基础排序.升序和降序.排序的稳定性和复杂排序.cmp函数排序法等内容,需要的朋友可以参考下 Python list内置so ...

  5. 4星|《OKR工作法》:关注公司的真正目标,以周为单位做计划和考核

    本书篇幅比较小,两个小时就可以看完.主要内容讲OKR工作法的基本概念,然后用一个虚拟的创业公司的创业故事来演示实施OKR过程中可能遇到的问题.OKR给创业带来的好处. OKR工作法相对来说是比较简单的 ...

  6. HDU_3732_(多重背包)

    Ahui Writes Word Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. HDU_3172_带权并查集

    Virtual Friends Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. POJ_3041_Asteroids

    参考自: http://user.qzone.qq.com/289065406/blog/1299322465 解题思路: 把方阵看做一个特殊的二分图(以行列分别作为两个顶点集V1.V2,其中| V1 ...

  9. python 3 Urllib 数据抓取

    1.0 Urllib简介 Urllib是python自带的标准库,无需安装,直接引用即可.urllib通常用于爬虫开发,API(应用程序编程接口)数据获取和测试.在python2和python3中,u ...

  10. PhpStorm 本地管理提交码云和GitHub代码仓库

    参考地址:https://www.yflad.cn/1766.html 1:下载Git客户端 2:打开PhpStorm,设置,Version Control → Git.配置git执行文件的路径.gi ...