【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

把序列生成的过程看成一颗树
会发现最后形成的是一颗二叉树。
每个二叉树上的节点就对应了序列中的一个数字。

如果我们把每个节点都往下投影的话。

(而且整棵树都是左右对称的。那么每个子树的根节点就是(l+r)/2了

就像是整个序列了。

(中序遍历

则我们可以用线段树求区间和的方法。

现在相当于告诉你1..n这个区间。

然后你要求l..r这个区间的和。

递归求就好。

【代码】

#include <bits/stdc++.h>
#define LL long long
using namespace std; LL n,l,r; LL dfs(LL n,LL L,LL R,LL l,LL r){
LL mid = (l+r)>>1;
LL temp = 0;
if (l==r) return n;
if (L<mid) temp+=dfs(n/2,L,R,l,mid-1);
if (mid<R) temp+=dfs(n/2,L,R,mid+1,r);
if(L<=mid && mid<=R) temp+=n%2;
return temp;
} int main()
{
cin >> n >> l >> r;
LL tot = 1,x = n;
while (x>1){
tot = tot + 1 + tot;
x>>=1;
}
cout<<dfs(n,l,r,1,tot)<<endl;
return 0;
}

【Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B】 Code For 1的更多相关文章

  1. 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

    打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> ...

  2. 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    直接暴力dp就行……f(i,j)表示前i天集齐j种类的可能性.不超过10000天就能满足要求. #include<cstdio> using namespace std; #define ...

  3. 【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number

    发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了. 复杂度O(k*1024). #include<cstdio> #include<c ...

  4. 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...

  5. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...

  6. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number

    地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...

  7. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...

  8. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch

    地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...

  9. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)

    C题卡了好久,A掉C题之后看到自己已经排在好后面说实话有点绝望,最后又过了两题,总算稳住了. AC:ABCDE Rank:191 Rating:2156+37->2193 A.Oath of t ...

随机推荐

  1. HDU 2079 选课时间(母函数模板题)

    链接:传送门 思路:母函数模板题 /************************************************************************* > Fil ...

  2. UVA1584-Circular Sequence(紫书例题3.6)

    Some DNA sequences exist in circular forms as in the following gure, which shows a circular sequence ...

  3. ansible 定义主机用户和密码

    定义主机组用户和密码 [webservers] ansible[01:04] ansible_ssh_user='root' ansible_ssh_pass='AAbb0101' [root@ftp ...

  4. oracle数据库安装教程以及问题和解决方法

    一,oracle数据库的下载和安装 1,在oracle官网上下载oracle安装包,运行setup.exe. 2,点击取消“我希望同构My Oracle Support接受安全更新”,以防后患. 3, ...

  5. 2019-03-19 SQL Server简单存储过程的创建 删除 执行

    --创建名为 Get 的有输入参数的存储过程 create proc Get --设置默认值 @TrustId int ='001' as begin select * from [DealStruc ...

  6. Java二维码打印

    http://blog.csdn.net/OnePersonTZ/article/details/66560513

  7. Winserver服务器-AD字段对照简图

    AD字段对照简图

  8. 《iOS Human Interface Guidelines》——System Button

    系统button 系统button运行一个app特定的动作. API NOTE 在iOS 7中,UIButtonTypeRoundedRect被又一次定义成UIButtonTypeSystem.查看U ...

  9. Windows身份验证和混合验证的差别

    两个验证方式的不同主要集中在信任连接和非信任连接.         windows 身份验证相对于混合模式更加安全,使用本连接模式时候,sql不推断sapassword.而仅依据用户的windows权 ...

  10. Hadoop解析--MapReduce

    从本篇博客開始咱们一起来具体了解Hadoop的每一个部分.我们在上篇博客中介绍了HDFS,MapReduce,MapReduce为了更有效率事实上是建立在HDFS之上的.有了分布式的文件系统,我们就能 ...